- repaired commandlog tail command (inserted SCPureSocketWrite)

- fixed mechanism for suppressing double lines in config listen mode
This commit is contained in:
zolliker
2009-02-25 14:47:33 +00:00
parent 2fd07071d9
commit 07bf425e50
2 changed files with 27 additions and 10 deletions

View File

@ -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);
}

View File

@ -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",
snprintf(pBueffel, sizeof 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);
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) {