From 07bf425e5056e74174db8abd421560b7ec0dfe40 Mon Sep 17 00:00:00 2001 From: zolliker Date: Wed, 25 Feb 2009 14:47:33 +0000 Subject: [PATCH] - repaired commandlog tail command (inserted SCPureSocketWrite) - fixed mechanism for suppressing double lines in config listen mode --- commandlog.c | 4 ++-- conman.c | 33 +++++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/commandlog.c b/commandlog.c index d158473d..08f239bc 100644 --- a/commandlog.c +++ b/commandlog.c @@ -244,8 +244,8 @@ static void PrintTail(int iNum, SConnection * pCon) */ for (i = 0; i < iNum; i++) { pPtr = (char *) getCircular(pTail); - if (pCon->pSock && pPtr != NULL) { - TelnetWrite(pCon->pSock, pPtr); + if (pPtr != NULL) { + SCPureSockWrite(pCon, pPtr, eWarning); } nextCircular(pTail); } diff --git a/conman.c b/conman.c index 26876b2c..f0372e6d 100644 --- a/conman.c +++ b/conman.c @@ -99,7 +99,7 @@ typedef struct { static int iName = 0; static long lastIdent = 0; /*------------- sending connection (prevent double write when listening) ----*/ -static SConnection *sendingConnection = NULL; +static int sendingConnection = 0; /*------------- storing connection and context for later use ----*/ struct SCStore { SConnection *pCon; @@ -679,10 +679,14 @@ static void testAndWriteCommandLog(SConnection * pCon, char *buffer, { if (SCGetRights(pCon) <= usUser) { if (SCinMacro(pCon) != 1) { + sendingConnection = pCon->sockHandle; WriteToCommandLogId(NULL, pCon->sockHandle, buffer); + sendingConnection = 0; } else { if (iOut == eLog || iOut == eLogError) { + sendingConnection = pCon->sockHandle; WriteToCommandLogId(NULL, pCon->sockHandle, buffer); + sendingConnection = 0; } } } @@ -910,6 +914,19 @@ int SCOnlySockWrite(SConnection * self, char *buffer, int iOut) return 1; } +/*--------------------------------------------------------------------------*/ +int SCPureSockWrite(SConnection * self, char *buffer, int iOut) +{ + /* for commandlog tail */ + if (!VerifyConnection(self)) { + return 0; + } + + testAndWriteSocket(self, buffer, iOut); + + return 1; +} + /*--------------------------------------------------------------------------*/ int SCNotWrite(SConnection * self, char *buffer, int iOut) { @@ -1337,13 +1354,13 @@ int SCInvoke(SConnection * self, SicsInterp * pInter, char *pCommand) * case */ if (SCGetWriteFunc(self) != SCNotWrite) { - sendingConnection = self; + sendingConnection = self->sockHandle; if (self->sockHandle >= 0) { WriteToCommandLogCmd(self->sockHandle, pCommand); } else { WriteToCommandLog("CRON>>", pCommand); } - sendingConnection = NULL; + sendingConnection = 0; } } @@ -1436,6 +1453,7 @@ int ConfigCon(SConnection * pCon, SicsInterp * pSics, void *pData, eError); return 0; } + pMaster->listening = pCon->listening; SCSendOK(pCon); return 1; } @@ -1500,10 +1518,9 @@ int ConfigCon(SConnection * pCon, SicsInterp * pSics, void *pData, if (CompactCommandLog()) { if (pCon->iUserRights < 3 || i < 3) { ANETinfo(pCon->sockHandle, pHost, sizeof pHost); - sprintf(pBueffel, "User %s from %s switched to %d privilege", - argv[2], pHost, i); - snprintf(pBueffel, 512, "User at %d switched to %d privilige", - pCon->sockHandle, i); + snprintf(pBueffel, sizeof pBueffel, + "User %s from %s switched to %d privilege", + argv[2], pHost, i); WriteToCommandLogId("SYS>", pCon->sockHandle, pBueffel); } } else { @@ -1888,7 +1905,7 @@ void SCSignalFunction(void *pData, int iSignal, void *pSigData) } } else if (iSignal == COMLOG && self->listening == 1) { pPtr = (char *) pSigData; - if (pPtr != NULL && self != sendingConnection) { + if (pPtr != NULL && self->sockHandle != sendingConnection) { doSockWrite(self, pPtr); } } else if (iSignal == TOKENRELEASE) {