- fixed some issues related to "config listen 1" mode

i.e. do not write some lines twice when in this mode
This commit is contained in:
zolliker
2013-06-07 06:17:07 +00:00
parent 9a142c18bf
commit 3f6a76052d
2 changed files with 32 additions and 10 deletions

View File

@ -68,6 +68,7 @@ void WriteToCommandLogId(char *prompt, int id, char *text)
time_t now; time_t now;
char stamp1[32], stamp2[32], buffer[80]; char stamp1[32], stamp2[32], buffer[80];
int doStamp, doStampId; int doStamp, doStampId;
int old;
/* suppress status messages */ /* suppress status messages */
if (strstr(text, "status =") != NULL) { if (strstr(text, "status =") != NULL) {
@ -196,6 +197,7 @@ void WriteToCommandLogId(char *prompt, int id, char *text)
if (pServ->pTasker != NULL) { if (pServ->pTasker != NULL) {
if (doStamp) { if (doStamp) {
TaskSignal(pServ->pTasker, COMLOG, stamp1); TaskSignal(pServ->pTasker, COMLOG, stamp1);
SCOnlySockWrite(GetSendingConnection(), stamp1, eLog);
} }
TaskSignal(pServ->pTasker, COMLOG, pCopy); TaskSignal(pServ->pTasker, COMLOG, pCopy);
} }

View File

@ -98,7 +98,8 @@ typedef struct {
static int iName = 0; static int iName = 0;
static long lastIdent = 0; static long lastIdent = 0;
/*------------- sending connection (prevent double write when listening) ----*/ /*------------- sending connection (prevent double write when listening) ----*/
static int sendingConnection = 0; static SConnection *sendingConnection = NULL;
static int sendingSockHandle = 0;
/*------------- storing connection and context for later use ----*/ /*------------- storing connection and context for later use ----*/
struct SCStore { struct SCStore {
SConnection *pCon; SConnection *pCon;
@ -139,6 +140,23 @@ void KillFreeConnections()
{ {
} }
/*---------------------------------------------------------------------------*/
SConnection *GetSendingConnection(void)
{
return sendingConnection;
}
/*---------------------------------------------------------------------------*/
static void SetSendingConnection(SConnection *pCon)
{
sendingConnection = pCon;
if (pCon) {
sendingSockHandle = pCon->sockHandle;
} else {
sendingSockHandle = 0;
}
}
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
static SConnection *SCMakeConnection() static SConnection *SCMakeConnection()
{ {
@ -700,14 +718,14 @@ static void testAndWriteCommandLog(SConnection * pCon, char *buffer,
{ {
if (SCGetRights(pCon) <= usUser) { if (SCGetRights(pCon) <= usUser) {
if (SCinMacro(pCon) != 1) { if (SCinMacro(pCon) != 1) {
sendingConnection = pCon->sockHandle; SetSendingConnection(pCon);
WriteToCommandLogId(NULL, pCon->sockHandle, buffer); WriteToCommandLogId(NULL, pCon->sockHandle, buffer);
sendingConnection = 0; SetSendingConnection(NULL);
} else { } else {
if (iOut == eLog || iOut == eLogError) { if (iOut == eLog || iOut == eLogError) {
sendingConnection = pCon->sockHandle; SetSendingConnection(pCon);
WriteToCommandLogId(NULL, pCon->sockHandle, buffer); WriteToCommandLogId(NULL, pCon->sockHandle, buffer);
sendingConnection = 0; SetSendingConnection(NULL);
} }
} }
} }
@ -1000,7 +1018,9 @@ int SCLogWrite(SConnection * self, char *buffer, int iOut)
if (!VerifyConnection(self)) { if (!VerifyConnection(self)) {
return 0; return 0;
} }
SetSendingConnection(self);
WriteToCommandLogId(NULL, self->sockHandle, buffer); WriteToCommandLogId(NULL, self->sockHandle, buffer);
SetSendingConnection(NULL);
if(self->iProtocolID == 5) { if(self->iProtocolID == 5) {
if (strlen(buffer) + 30 > 1024) { if (strlen(buffer) + 30 > 1024) {
@ -1614,7 +1634,7 @@ int SCInvoke(SConnection * self, SicsInterp * pInter, char *pCommand)
* case * case
*/ */
if (SCGetWriteFunc(self) != SCNotWrite) { if (SCGetWriteFunc(self) != SCNotWrite) {
sendingConnection = self->sockHandle; SetSendingConnection(self);
if (self->sockHandle >= 0) { if (self->sockHandle >= 0) {
if(strstr(pCommand,"Poch") == NULL){ if(strstr(pCommand,"Poch") == NULL){
WriteToCommandLogCmd(self->sockHandle, pCommand); WriteToCommandLogCmd(self->sockHandle, pCommand);
@ -1622,7 +1642,7 @@ int SCInvoke(SConnection * self, SicsInterp * pInter, char *pCommand)
} else { } else {
WriteToCommandLog("CRON>>", pCommand); WriteToCommandLog("CRON>>", pCommand);
} }
sendingConnection = 0; SetSendingConnection(NULL);
} }
} }
@ -2164,11 +2184,11 @@ void SCSignalFunction(void *pData, int iSignal, void *pSigData)
} else if (iSignal == SICSBROADCAST) { } else if (iSignal == SICSBROADCAST) {
pPtr = (char *) pSigData; pPtr = (char *) pSigData;
if (pPtr != NULL) { if (pPtr != NULL) {
SCWrite(self, pPtr, eWarning); SCPureSockWrite(self, pPtr, eWarning);
} }
} else if (iSignal == COMLOG && self->listening == 1) { } else if (iSignal == COMLOG && self->listening == 1) {
pPtr = (char *) pSigData; pPtr = (char *) pSigData;
if (pPtr != NULL && self->sockHandle != sendingConnection) { if (pPtr != NULL && self->sockHandle != sendingSockHandle) {
doSockWrite(self, pPtr); doSockWrite(self, pPtr);
} }
} else if (iSignal == TOKENRELEASE) { } else if (iSignal == TOKENRELEASE) {