diff --git a/SCinter.c b/SCinter.c index 87695dc8..698ab222 100644 --- a/SCinter.c +++ b/SCinter.c @@ -72,14 +72,12 @@ #include "fortify.h" #include "sics.h" #include "splitter.h" -#include "servlog.h" #include "macro.h" #include "interface.h" #include "motor.h" #include "obdes.h" #include "lld.h" #include "dynstring.h" -#include "commandlog.h" /* M.Z. */ #include "definealias.h" @@ -101,7 +99,7 @@ SicsInterp *InitInterp(void) pInter = (SicsInterp *) malloc(sizeof(SicsInterp)); if (!pInter) { - SICSLogWrite("Error allocating memory for Interpreter", eInternal); + Log(FATAL,"sys","Error allocating memory for Interpreter"); return NULL; } memset(pInter, 0, sizeof(SicsInterp)); @@ -140,7 +138,7 @@ int AddCommandWithFlag(SicsInterp * pInterp, char *pName, ObjectFunc pFunc, pNew = (CommandList *) malloc(sizeof(CommandList)); if (!pNew) { snprintf(pBueffel,sizeof(pBueffel)-1, "Out of memory creating command - %s -", pName); - SICSLogWrite(pBueffel, eInternal); + Log(ERROR,"sys","%s",pBueffel); return 0; } memset(pNew, 0, sizeof(CommandList)); @@ -296,7 +294,7 @@ int InterpExecute(SicsInterp * self, SConnection * pCon, char *pText) assert(self); assert(pCon); - /* write info to Log */ + /* write info to Log if (pCon->sockHandle >= 0) { snprintf(pBueffel,1023, "Executing -> %s <- from socket %d", pText, pCon->sockHandle); @@ -306,6 +304,11 @@ int InterpExecute(SicsInterp * self, SConnection * pCon, char *pText) SICSLogWrite(pBueffel, eCommand); } + TODO: disabled for now. This is a duplication of what is logged in SCInvoke. + + Mark Koennecke, February 2016 + */ + if(strstr(pText,tclescape) == pText){ return TclExecFunc(pCon,self,NULL,pText); } @@ -361,7 +364,7 @@ int InterpExecute(SicsInterp * self, SConnection * pCon, char *pText) * log in history if succesfull */ if(iRet == 1){ - WriteCommandHistory(pText); + Log(DEBUG,"history","%s",pText); } diff --git a/SICSmain.c b/SICSmain.c index 3df779cc..bf707aaa 100644 --- a/SICSmain.c +++ b/SICSmain.c @@ -22,7 +22,8 @@ #include #include #include "nserver.h" -#include "servlog.h" +#include "logv2.h" + extern void KeepStartupCommands(); /* ofac.c */ @@ -62,7 +63,7 @@ int main(int argc, char *argv[]) for (i = firstArg; i < argc; i++) { if (argv[i][0] == '-') { if (strcasecmp(argv[i], "-nolog") == 0) { - SICSLogEnable(0); + DisableLog(); }else if(strcmp(argv[i],"-keepstartup") == 0){ KeepStartupCommands(); #ifdef SITE_ANSTO diff --git a/asyncprotocol.c b/asyncprotocol.c index cdfeae05..f9aa909b 100644 --- a/asyncprotocol.c +++ b/asyncprotocol.c @@ -81,8 +81,7 @@ int defaultPrepareTxn(pAsyncProtocol p, pAsyncTxn txn, const char *cmd, /* outgoing command is correctly terminated */ txn->out_buf = malloc(cmd_len + 1); if (txn->out_buf == NULL) { - SICSLogWrite("Out of memory in AsyncProtocol::defaultPrepareTxn", - eError); + Log(ERROR,"ASQUIO","%s","Out of memory in AsyncProtocol::defaultPrepareTxn"); return 0; } memcpy(txn->out_buf, cmd, cmd_len + 1); @@ -91,7 +90,7 @@ int defaultPrepareTxn(pAsyncProtocol p, pAsyncTxn txn, const char *cmd, int tlen = strlen(term); txn->out_buf = malloc(cmd_len + tlen + 1); if (txn->out_buf == NULL) { - SICSLogWrite("Out of memory in AsyncProtocol::defaultPrepareTxn", + Log(ERROR,"ASQUIO","%s","Out of memory in AsyncProtocol::defaultPrepareTxn", eError); return 0; } @@ -174,7 +173,7 @@ static char *decodeTerminator(char *code) count = strlen(code); pResult = (char *) malloc(count + 1); if (!pResult) { - SICSLogWrite("Out of memory in AsyncProtocol::decodeTerminator", + Log(ERROR,"ASQUIO","%s","Out of memory in AsyncProtocol::decodeTerminator", eError); return NULL; } @@ -329,7 +328,7 @@ pAsyncProtocol AsyncProtocolCreate(SicsInterp * pSics, self = (pAsyncProtocol) malloc(sizeof(AsyncProtocol)); if (self == NULL) { - SICSLogWrite("Out of memory in AsyncProtocolCreate", eError); + Log(ERROR,"ASQUIO","%s","Out of memory in AsyncProtocolCreate"); return NULL; } memset(self, 0, sizeof(AsyncProtocol)); @@ -340,7 +339,7 @@ pAsyncProtocol AsyncProtocolCreate(SicsInterp * pSics, pKFunc = AsyncProtocolKill; iRet = AddCommand(pSics, (char *) protocolName, pFunc, pKFunc, self); if (!iRet) { - SICSLogWrite("AddCommand failed in AsyncProtocolCreate", eError); + Log(ERROR,"ASQUIO","%s","AddCommand failed in AsyncProtocolCreate"); AsyncProtocolKill(self); return NULL; } diff --git a/asyncqueue.c b/asyncqueue.c index f42684e8..ed16849f 100644 --- a/asyncqueue.c +++ b/asyncqueue.c @@ -207,7 +207,7 @@ static void AQ_Notify(pAsyncQueue self, int event) { pAsyncUnit unit; if (self->state != eAsyncConnected) - SICSLogPrintf(eStatus, "Function: %s:%s\n", self->queue_name, + Log(DEBUG,"ASQUIO", "Function:%s:%s", self->queue_name, __func__); for (unit = self->units; unit; unit = unit->next) if (unit->notify_func != NULL) @@ -222,7 +222,7 @@ static int TimedReconnect(void *cntx, int mode) self->nw_tmr = 0; if (self->state != eAsyncConnected) - SICSLogPrintf(eStatus, "Function: %s:%s\n", self->queue_name, + Log(DEBUG,"ASQUIO", "Function: %s:%s\n", self->queue_name, __func__); AQ_Purge(self); @@ -240,7 +240,7 @@ static int TimedReconnect(void *cntx, int mode) if (iRet < 0) { snprintf(line, 132, "Failed reconnect on AsyncQueue '%s'", self->queue_name); - SICSLogWrite(line, eStatus); + Log(DEBUG,"ASQUIO","%s",line); /* Timer for retry */ NetWatchSetMode(self->nw_ctx, 0); /* implement an exponential backoff within limits */ @@ -251,12 +251,12 @@ static int TimedReconnect(void *cntx, int mode) self->retryTimer = 16000; AQ_SetTimer(self, self->retryTimer, TimedReconnect, self); - SICSLogPrintf(eStatus, "In %s:%s: state %s => eAsyncWaiting\n", + Log(DEBUG,"ASQUIO", "In %s:%s: state %s => eAsyncWaiting", self->queue_name, __func__, state_name(self->state)); self->state = eAsyncWaiting; } else { NetWatchSetMode(self->nw_ctx, nwatch_write); - SICSLogPrintf(eStatus, "In %s:%s: state %s => eAsyncConnecting\n", + Log(DEBUG,"ASQUIO", "In %s:%s: state %s => eAsyncConnecting\n", self->queue_name, __func__, state_name(self->state)); self->state = eAsyncConnecting; /* await reconnect result in MyCallback */ @@ -264,11 +264,11 @@ static int TimedReconnect(void *cntx, int mode) return 1; } NetWatchSetMode(self->nw_ctx, nwatch_read); - SICSLogPrintf(eStatus, "In %s:%s: state %s => eAsyncConnected\n", + Log(DEBUG,"ASQUIO", "In %s:%s: state %s => eAsyncConnected\n", self->queue_name, __func__, state_name(self->state)); self->state = eAsyncConnected; snprintf(line, 132, "Reconnect on AsyncQueue '%s'", self->queue_name); - SICSLogWrite(line, eStatus); + Log(DEBUG,"ASQUIO","%s",line); AQ_Purge(self); AQ_Notify(self, AQU_RECONNECT); return 1; @@ -280,7 +280,7 @@ static int AQ_Reconnect(pAsyncQueue self) char line[132]; if (self->state != eAsyncConnected) - SICSLogPrintf(eStatus, "Function: %s:%s\n", self->queue_name, + Log(DEBUG,"ASQUIO", "Function: %s:%s\n", self->queue_name, __func__); /* * Remove any old timer @@ -290,7 +290,7 @@ static int AQ_Reconnect(pAsyncQueue self) if (self->state == eAsyncConnected) { self->state = eAsyncIdle; - SICSLogPrintf(eStatus, "Disconnect on AsyncQueue '%s'", self->queue_name); + Log(DEBUG,"ASQUIO", "Disconnect on AsyncQueue '%s'", self->queue_name); AQ_Notify(self, AQU_DISCONNECT); AQ_Purge(self); } @@ -310,12 +310,12 @@ static int AQ_Reconnect(pAsyncQueue self) self->retryTimer = 125; /* initial delay */ AQ_SetTimer(self, self->retryTimer, TimedReconnect, self); - SICSLogPrintf(eStatus, "In %s:%s: state %s => eAsyncWaiting\n", + Log(DEBUG,"ASQUIO", "In %s:%s: state %s => eAsyncWaiting\n", self->queue_name, __func__, state_name(self->state)); self->state = eAsyncWaiting; } else { NetWatchSetMode(self->nw_ctx, nwatch_write); - SICSLogPrintf(eStatus, "In %s:%s: state %s => eAsyncConnecting\n", + Log(DEBUG,"ASQUIO", "In %s:%s: state %s => eAsyncConnecting\n", self->queue_name, __func__, state_name(self->state)); self->state = eAsyncConnecting; /* await reconnect result in MyCallback */ @@ -323,11 +323,11 @@ static int AQ_Reconnect(pAsyncQueue self) return iRet; } NetWatchSetMode(self->nw_ctx, nwatch_read); - SICSLogPrintf(eStatus, "In %s:%s: state %s => eAsyncConnected\n", + Log(DEBUG,"ASQUIO", "In %s:%s: state %s => eAsyncConnected\n", self->queue_name, __func__, state_name(self->state)); self->state = eAsyncConnected; snprintf(line, 132, "Reconnect on AsyncQueue '%s'", self->queue_name); - SICSLogWrite(line, eStatus); + Log(DEBUG,"ASQUIO",line); AQ_Purge(self); AQ_Notify(self, AQU_RECONNECT); return 1; @@ -344,7 +344,7 @@ static int StartCommand(pAsyncQueue self) int iRet = 0; if (self->state != eAsyncConnected) - SICSLogPrintf(eStatus, "Function: %s:%s\n", self->queue_name, + Log(DEBUG,"ASQUIO", "Function: %s:%s\n", self->queue_name, __func__); if (myCmd == NULL) return OKOK; @@ -393,10 +393,7 @@ static int StartCommand(pAsyncQueue self) } else if (iRet > 0) { struct timeval tv; gettimeofday(&tv, NULL); - SICSLogTimePrintf(eError, &tv, - "ERROR: %d unsolicited chars in AsyncQueue %s", - iRet, self->queue_name); - SICSLogWriteHexTime(reply, iRet, eError, &tv); + Log(ERROR, "ASQUIO","%d unsolicited chars in AsyncQueue %s",iRet, self->queue_name); } } } @@ -504,9 +501,7 @@ static int CommandTimeout(void *cntx, int mode) if (self->trace) { struct timeval tv; gettimeofday(&tv, NULL); - SICSLogTimePrintf(eLog, &tv, - "Timeout Trace on AsyncQueue %s", self->queue_name); - SICSLogWriteHexTime(myCmd->tran->inp_buf, myCmd->tran->inp_idx, eLog, &tv); + Log(DEBUG,"ASQUIO", "Timeout Trace on AsyncQueue %s", self->queue_name); } if (myCmd->retries > 0) { --myCmd->retries; @@ -530,7 +525,7 @@ static int DelayedStart(void *cntx, int mode) { pAsyncQueue self = (pAsyncQueue) cntx; if (self->state != eAsyncConnected) - SICSLogPrintf(eStatus, "Function: %s:%s\n", self->queue_name, + Log(DEBUG,"ASQUIO", "Function: %s:%s\n", self->queue_name, __func__); self->nw_tmr = 0; StartCommand(self); @@ -542,7 +537,7 @@ static int MyCallback(void *context, int mode) pAsyncQueue self = (pAsyncQueue) context; if (self->state != eAsyncConnected) - SICSLogPrintf(eStatus, "Function: %s:%s\n", self->queue_name, + Log(DEBUG,"ASQUIO", "Function: %s:%s\n", self->queue_name, __func__); if (mode & nwatch_read) { int iRet; @@ -572,9 +567,8 @@ static int MyCallback(void *context, int mode) if (self->trace) { struct timeval tv; gettimeofday(&tv, NULL); - SICSLogTimePrintf(eLog, &tv, - "Input Trace on AsyncQueue %s", self->queue_name); - SICSLogWriteHexTime(myCmd->tran->inp_buf, myCmd->tran->inp_idx, eLog, &tv); + Log(INFO, "ASQUIO", + "Received:%s:%s", self->queue_name,myCmd->tran->inp_buf); } PopCommand(self); break; @@ -582,18 +576,10 @@ static int MyCallback(void *context, int mode) int excess = nchars - 1 - i; struct timeval tv; gettimeofday(&tv, NULL); - SICSLogTimePrintf(eError, &tv, - "ERROR: Protocol error %d in AsyncQueue %s", + Log(ERROR,"ASQUIO", + "Protocol error %d in AsyncQueue %s", iRet, self->queue_name); - SICSLogWriteTime("Sent:", eError, &tv); - SICSLogWriteHexTime(myCmd->tran->out_buf, myCmd->tran->out_len, eError, &tv); - SICSLogWriteTime("Received:", eError, &tv); - SICSLogWriteHexTime(myCmd->tran->inp_buf, myCmd->tran->inp_idx, eError, &tv); - SICSLogWriteTime("Processed:", eError, &tv); - SICSLogWriteHexTime(&reply[0], i, eError, &tv); - SICSLogWriteTime("Unprocessed:", eError, &tv); - SICSLogWriteHexTime(&reply[i], excess, eError, &tv); - /* TODO: error */ + Log(ERROR,"ASQUIO","SENT:%s:Received:%s",myCmd->tran->out_buf, myCmd->tran->inp_buf); break; } } @@ -601,30 +587,26 @@ static int MyCallback(void *context, int mode) int excess = nchars - 1 - i; struct timeval tv; gettimeofday(&tv, NULL); - SICSLogTimePrintf(eError, &tv, - "ERROR: %d excess chars in AsyncQueue %s", + Log(ERROR, "ASQUIO", "%d excess chars in AsyncQueue %s", excess, self->queue_name); - SICSLogWriteHexTime(&reply[i], excess, eError, &tv); /* TODO: handle unsolicited */ } } else { int excess = nchars - 1 - i; struct timeval tv; gettimeofday(&tv, NULL); - SICSLogTimePrintf(eError, &tv, - "ERROR: %d unsolicited chars in AsyncQueue %s", + Log(ERROR, "ASQUIO", "%d unsolicited chars in AsyncQueue %s", excess, self->queue_name); - SICSLogWriteHexTime(&reply[i], excess, eError, &tv); /* TODO: handle unsolicited input */ } } } if (mode & nwatch_write) { char line[132]; - SICSLogPrintf(eStatus, "Writeable socket callback on AsyncQueue %s", + Log(DEBUG,"ASQUIO", "Writeable socket callback on AsyncQueue %s", self->queue_name); NetWatchSetMode(self->nw_ctx, nwatch_read); - SICSLogPrintf(eStatus, "In %s:%s: state %s => eAsyncConnected\n", + Log(DEBUG,"ASQUIO", "In %s:%s: state %s => eAsyncConnected\n", self->queue_name, __func__, state_name(self->state)); self->state = eAsyncConnected; } @@ -638,7 +620,7 @@ int AsyncUnitEnqueueHead(pAsyncUnit unit, pAsyncTxn context) assert(unit && unit->queue && unit->queue->protocol); myCmd = (pAQ_Cmd) malloc(sizeof(AQ_Cmd)); if (myCmd == NULL) { - SICSLogWrite("ERROR: Out of memory in AsyncUnitEnqueHead", eError); + Log(ERROR,"ASQUIO","Out of memory in AsyncUnitEnqueHead", eError); return 0; } memset(myCmd, 0, sizeof(AQ_Cmd)); @@ -657,7 +639,7 @@ int AsyncUnitEnqueueTxn(pAsyncUnit unit, pAsyncTxn pTxn) assert(unit && unit->queue && unit->queue->protocol); myCmd = (pAQ_Cmd) malloc(sizeof(AQ_Cmd)); if (myCmd == NULL) { - SICSLogWrite("ERROR: Out of memory in AsyncUnitEnqueueTxn", eError); + Log(ERROR,"ASQUIO","%s","Out of memory in AsyncUnitEnqueueTxn"); return 0; } memset(myCmd, 0, sizeof(AQ_Cmd)); @@ -679,7 +661,7 @@ pAsyncTxn AsyncUnitPrepareTxn(pAsyncUnit unit, assert(unit); myTxn = (pAsyncTxn) malloc(sizeof(AsyncTxn)); if (myTxn == NULL) { - SICSLogWrite("ERROR: Out of memory in AsyncUnitPrepareTxn", eError); + Log(ERROR,"ASQUIO","%s","Out of memory in AsyncUnitPrepareTxn", eError); return NULL; } memset(myTxn, 0, sizeof(AsyncTxn)); @@ -714,7 +696,7 @@ pAsyncTxn AsyncUnitPrepareTxn(pAsyncUnit unit, } else { myTxn->out_buf = (char *) malloc(cmd_len + 5); if (myTxn->out_buf == NULL) { - SICSLogWrite("ERROR: Out of memory in AsyncUnitPrepareTxn", eError); + Log(ERROR,"ASQUIO","%s","Out of memory in AsyncUnitPrepareTxn"); free(myTxn); return NULL; } @@ -733,7 +715,7 @@ pAsyncTxn AsyncUnitPrepareTxn(pAsyncUnit unit, else { myTxn->inp_buf = malloc(rsp_len + 1); if (myTxn->inp_buf == NULL) { - SICSLogWrite("ERROR: Out of memory in AsyncUnitPrepareTxn", eError); + Log(ERROR,"ASQUIO","%s","Out of memory in AsyncUnitPrepareTxn", eError); free(myTxn->out_buf); free(myTxn); return NULL; @@ -831,9 +813,8 @@ int AsyncUnitWrite(pAsyncUnit unit, void *buffer, int buflen) if (unit->queue->trace) { struct timeval tv; gettimeofday(&tv, NULL); - SICSLogTimePrintf(eLog, &tv, - "Output Trace on AsyncQueue %s", unit->queue->queue_name); - SICSLogWriteHexTime(buffer, buflen, eLog, &tv); + Log(DEBUG,"ASQUIO" + "Output Trace on AsyncQueue %s:%s", unit->queue->queue_name, buffer); } sock = AsyncUnitGetSocket(unit); iRet = NETWrite(sock, buffer, buflen); @@ -1399,7 +1380,7 @@ int AsyncUnitCreateHost(const char *host, const char *port, unit = (pAsyncUnit) malloc(sizeof(AsyncUnit)); if (unit == NULL) { - SICSLogWrite("ERROR: Out of memory in AsyncUnitCreateHost", eError); + Log(ERROR,"ASQUIO","%s","Out of memory in AsyncUnitCreateHost", eError); *handle = NULL; return 0; } diff --git a/commandlog.c b/commandlog.c deleted file mode 100644 index 06d5bd54..00000000 --- a/commandlog.c +++ /dev/null @@ -1,652 +0,0 @@ -/*-------------------------------------------------------------------------- - C O M M A N D L O G - - A much requested facility for writing only user and manager level commands - in a transcript file. This is it. - - Mark Koennecke, June 1998 - - Extended to support Heinz Heers autolog-file - Mark Koennecke, April-May 1999 - - Added a tail facility - Mark Koennecke, October 1999 - - Added compact mode: - - timestamps look different and are omitted if no other text is written - - socket number information is written on the timestamp line - - Added command history logging. Due to problems this is currently disabled by - writeHistory = 0 and code in SetWriteHistory - - Mark Koennecke, July 2010 ---------------------------------------------------------------------------*/ -#include -#include -#include -#include -#include -#include "splitter.h" -#include "sics.h" -#include "ifile.h" -#include "sicsvar.h" -#include "scaldate.h" -#include "network.h" -#include "circular.h" -#include "stptok.h" - -/* in conman.c */ -int TelnetWrite(mkChannel * pSock, char *pText); -/*-------------------- the command log file pointer ---------------------*/ -static FILE *fd = NULL; -static FILE *fauto = NULL; -static char pFile[256]; -/*------------------------- command history logging --------------------*/ -static char pHistoryFilter[1024] = ""; -static int writeHistory = 0; -/*-------------------- the tail buffer ---------------------------------*/ -static pCircular pTail = NULL; -#define MAXTAIL 1000 -#define NOID -1964 -static time_t lastStamp = 0; -static time_t iCompact = 0; -static time_t tLastWrite = 0; -char *cmdPrompt = ">"; -static int lastId = NOID; - -static time_t tLogfile = 0; -static time_t tStamp = 0; -static int iEnd = 1; -static int iAutoActive = 0; -static int iIntervall = 60; -/*----------------------------------------------------------------------*/ -void WriteToCommandLogId(char *prompt, int id, char *text) -{ - int l, iPos; - char *pPtr = NULL, *pCopy = NULL, *strippedText = text; - struct tm *nowTm; - time_t now; - char stamp1[32], stamp2[32], buffer[80]; - int doStamp, doStampId; - int old; - - /* suppress status messages */ - if (strstr(text, "status =") != NULL) { - return; - } - - /* suppress TRANSACTIONFINISHED as well in order to make the WWW - commandlog work and TRANSACTIONSTART in order to make the logfiles - shorter - */ - if (strstr(text, "TRANSACTIONSTART") != NULL) { - return; - } - if (strstr(text, "TRANSACTIONFINISHED") != NULL) { - return; - } - - /* we make a local copy, stripping off the newline at the - end. We anyway need a copy later for the circular buffer */ - l = strlen(text); - pPtr = strrchr(text, '\n'); - if (pPtr != NULL && (pPtr[1] == '\0' || pPtr[2] == '\0')) { - l = pPtr - text; - } - pCopy = malloc(l + 1); - if (pCopy == NULL) - return; - strncpy(pCopy, text, l); /* strlcpy is not correct here */ - pCopy[l] = '\0'; - if (prompt == cmdPrompt && iCompact) { - pPtr = strstr(pCopy, "fulltransact "); - if (pPtr && pPtr < pCopy + 3) { - strippedText = pPtr + 13; - } - pPtr = strstr(pCopy, "transact "); - if (pPtr && pPtr < pCopy + 3) { - strippedText = pPtr + 9; - } - } - - now = time(NULL); - - /* create tail buffer as needed */ - if (!pTail) { - pTail = createCircular(MAXTAIL, free); - } - - doStamp = 0; - doStampId = 0; - - if (iCompact == 1) { - nowTm = localtime(&now); - strftime(stamp1, sizeof stamp1, "%H:%M:%S", nowTm); - if (prompt == NULL) - prompt = ""; - if (id == NOID) { - if (!prompt) - prompt = " "; - snprintf(buffer, sizeof buffer, "%s %s ", stamp1, prompt); - } else { - snprintf(buffer, sizeof buffer, "%s %2.0d| ", stamp1, id); - } - prompt = buffer; - } else if (id == NOID) { - if (!prompt) { - prompt = ""; - } else { - snprintf(buffer, sizeof buffer, "%s ", prompt); - prompt = buffer; - } - } else if (iCompact == 0) { - if (!prompt) { - snprintf(buffer, sizeof buffer, "To sock %d : ", id); - } else { - snprintf(buffer, sizeof buffer, "sock %d>%s ", id, prompt); - } - prompt = buffer; - } else if (iCompact > 1) { - if (id != lastId) { - lastId = id; - doStampId = 1; - } - if (!prompt) { - prompt = ""; - } else { - snprintf(buffer, sizeof buffer, "%s ", prompt); - prompt = buffer; - } - } - - if (iCompact > 1) { /* write time stamp */ - if (now / iCompact != lastStamp / iCompact) { - doStamp = 1; - doStampId = 1; - } - if (doStampId) { - lastStamp = now; - nowTm = localtime(&now); - strftime(stamp1, sizeof stamp1, "=== %H:%M:%S ===", nowTm); - if (id != NOID) { - snprintf(stamp2, sizeof stamp2, " socket %d ===", id); - } else { - stamp2[0] = '\0'; - } - } - } - - /* user file */ - if (fd != NULL) { - if (doStampId) { - fprintf(fd, "%s %s\n", stamp1, stamp2); - } - fprintf(fd, "%s%s\n", prompt, pCopy); - } - - /* automatic file */ - if (fauto != NULL) { - tLastWrite = now; - if (doStampId) { - fprintf(fauto, "%s%s\n", stamp1, stamp2); - } - fprintf(fauto, "%s%s\n", prompt, strippedText); - } - - /* to all listening sockets. The check is necessary to resolve a shutdown problem */ - if (pServ->pTasker != NULL) { - if (doStamp) { - TaskSignal(pServ->pTasker, COMLOG, stamp1); - SCOnlySockWrite(GetSendingConnection(), stamp1, eLog); - } - TaskSignal(pServ->pTasker, COMLOG, pCopy); - } - - /* tail buffer */ - if (pTail != NULL) { - if (doStamp) { - setCircular(pTail, strdup(stamp1)); - nextCircular(pTail); - } - setCircular(pTail, strdup(pCopy)); - nextCircular(pTail); - } - lastId = id; - if(pCopy != NULL){ - free(pCopy); - } -} - -/*------------------------------------------------------------------------*/ -void WriteToCommandLog(char *prompt, char *text) -{ - WriteToCommandLogId(prompt, NOID, text); -} - -/*------------------------------------------------------------------------*/ -void WriteToCommandLogCmd(int id, char *text) -{ - WriteToCommandLogId(cmdPrompt, id, text); -} - -/*------------------------------------------------------------------------*/ -int CompactCommandLog(void) -{ - return iCompact > 0; -} - -/*------------------------------------------------------------------------*/ -static void PrintTail(int iNum, SConnection * pCon) -{ - char *pPtr = NULL; - int i; - - if (pTail == NULL) { - SCWrite(pCon, "Nothing to print", eError); - return; - } - - /* step back */ - for (i = 0; i < iNum; i++) { - previousCircular(pTail); - } - - /* now step ahead and print. I have to use a trick here: I do not - want the tail stuff to show up in log files. Thus I write it - directly to the connection socket. - */ - for (i = 0; i < iNum; i++) { - pPtr = (char *) getCircular(pTail); - if (pPtr != NULL) { - SCPureSockWrite(pCon, pPtr, eWarning); - } - nextCircular(pTail); - } -} - -/*------------------------------------------------------------------------*/ -void CLFormatTime(char *pBuffer, int iBufLen) -{ - time_t iDate; - struct tm *psTime; - - /* make time string */ - iDate = time(NULL); - psTime = localtime(&iDate); - memset(pBuffer, 0, iBufLen); - strftime(pBuffer, iBufLen, "%Y-%m-%d@%H-%M-%S", psTime); -} - -/*---------------------------------------------------------------------- - Build an automatically generated log file name and open it. -*/ -static void AutoLog(void) -{ - char pBueffel[1024]; - char pTime[80]; - pSicsVariable pInst = NULL; - char *pPtr = NULL; - SConnection *pIntern = NULL; - - if (fauto) { - fclose(fauto); - fauto = NULL; - } - - /* find path */ - pPtr = IFindOption(pSICSOptions, "LogFileDir"); - if (!pPtr) { - pPtr = strdup("~/log"); - printf("WARNING: Required SICS option LogFileDir not found"); - } - - /* get time */ - CLFormatTime(pTime, 79); - - /* build file name */ - snprintf(pBueffel,1024, "%s/auto%s.log", pPtr, pTime); - - /* open file */ - fauto = fopen(pBueffel, "w"); - if (!fauto) { - ServerWriteGlobal("ERROR: failed to open autolog file", eError); - } - - /* write the instrument name to it for identification */ - pInst = FindVariable(pServ->pSics, "instrument"); - if (pInst) { - snprintf(pBueffel,1024, "Logfile started at instrument %s at %s", - pInst->text, pTime); - WriteToCommandLog("SYS>>", pBueffel); - } - - /* if a file to execute is configured, execute it */ - pPtr = NULL; - pPtr = IFindOption(pSICSOptions, "logstartfile"); - if (pPtr != NULL) { - pIntern = SCCreateDummyConnection(pServ->pSics); - if (!pIntern) { - return; - } - SCnoSock(pIntern); - SCSetRights(pIntern, usUser); - snprintf(pBueffel,1024, "fileeval %s", pPtr); - InterpExecute(pServ->pSics, pIntern, pBueffel); - SCDeleteConnection(pIntern); - } -} - -/*---------------------------------------------------------------------- - AutoTask puts a time stamp into the auto log file any hour and - creates a new log file any 24 hours -*/ -static int AutoTask(void *pData) -{ - time_t tNow; - char pTime[80]; - struct tm *sTime; - long julian; - unsigned yr, mo, dd; - - tNow = time(NULL); - if (tNow > tLogfile) { - AutoLog(); - sTime = localtime(&tNow); - /* find next day, do so by converting to julian Date, add one - and calculate back. The (stolen) julian calculations will - take care of all the leaps and month and year etc. - */ - julian = ymd_to_scalar(sTime->tm_year + 1900, sTime->tm_mon + 1, - sTime->tm_mday); - julian++; - scalar_to_ymd(julian, &yr, &mo, &dd); - sTime->tm_sec = 0; - sTime->tm_min = 1; - sTime->tm_hour = 0; - sTime->tm_mday = dd; - sTime->tm_mon = mo - 1; - sTime->tm_year = yr - 1900; - tLogfile = mktime(sTime); - if (tLogfile < 0) - tLogfile = tNow + 60 * 60 * 24; - } - if (tNow > tStamp && iIntervall > 0) { - CLFormatTime(pTime, 79); - WriteToCommandLog("TIMESTAMP>> ", pTime); - sTime = localtime(&tNow); - sTime->tm_sec = 0; - sTime->tm_min += iIntervall; - if (sTime->tm_min >= 60) { - sTime->tm_min = 0; - sTime->tm_hour++; - } - if (sTime->tm_hour >= 24) - sTime->tm_hour = 0; - tStamp = mktime(sTime); - if ((tStamp < 0) || ((tStamp - tNow) < 100)) { - tStamp = tNow + iIntervall * 60; - } - if (fauto) - fflush(fauto); - } - - if (fauto && tLastWrite > 0 && tNow > tLastWrite) { - fflush(fauto); - tLastWrite = 0; - } - return iEnd; -} - -/*----------- a command to configure the log --------------------------*/ -int CommandLog(SConnection * pCon, SicsInterp * pSics, void *pData, - int argc, char *argv[]) -{ - char *pPtr = NULL; - char pBueffel[1024]; - int iVal, iRet; - - if (argc == 1) { - if (fd) { - sprintf(pBueffel, "Command log ACTIVE at %s", pFile); - SCWrite(pCon, pBueffel, eValue); - return 1; - } else { - SCWrite(pCon, "Command logging DISABLED", eValue); - return 1; - } - } - - /* handle tail */ - strtolower(argv[1]); - if (strcmp(argv[1], "tail") == 0) { - /* check for optional number of lines argument */ - iVal = 20; - if (argc >= 3) { - iRet = Tcl_GetInt(pSics->pTcl, argv[2], &iVal); - if (iRet != TCL_OK) - iVal = 20; - } - PrintTail(iVal, pCon); - return 1; - } - /** - * handle write - */ - - if (strcmp(argv[1], "write") == 0) { - Arg2Text(argc-2, &argv[2],pBueffel,sizeof(pBueffel)); - WriteToCommandLogId(NULL, pCon->sockHandle,pBueffel); - SCSendOK(pCon); - return 1; - } - - /* check rights */ - if (!SCMatchRights(pCon, usMugger)) { - SCWrite(pCon, "ERROR: only managers may configure the logfile", - eError); - SCWrite(pCon, "ERROR: Request refused", eError); - return 0; - } - - /* check no of args */ - if (argc < 2) { - SCWrite(pCon, - "ERROR: Insufficient number or arguments to commandlog", - eError); - return 0; - } - - if (strcmp(argv[1], "new") == 0) { /* new command */ - if (argc < 3) { - SCWrite(pCon, - "ERROR: Insufficient number or arguments to commandlog new", - eError); - return 0; - } - if (fd) { - fclose(fd); - fd = NULL; - } - /* make the filename */ - pPtr = IFindOption(pSICSOptions, "LogFileDir"); - if (!pPtr) { - SCWrite(pCon, "WARNING: no log file directory specified", eWarning); - snprintf(pBueffel,1023, "%s", argv[2]); - - } else { - snprintf(pBueffel,1023, "%s/%s", pPtr, argv[2]); - } - fd = fopen(pBueffel, "w"); - if (!fd) { - snprintf(pBueffel,1023, "ERROR: cannot open %s/%s for writing", pPtr, - argv[2]); - SCWrite(pCon, pBueffel, eError); - return 0; - } - strlcpy(pFile, argv[2],255); - SCSendOK(pCon); - return 1; - } else if (strcmp(argv[1], "auto") == 0) { - if (iAutoActive) { - SCWrite(pCon, "ERROR: autologging is already active", eError); - return 0; - } - TaskRegisterN(pServ->pTasker, "autologger", AutoTask, NULL, NULL, NULL, TASK_PRIO_HIGH); - SCSendOK(pCon); - iAutoActive = 1; - return 1; - } else if (strcmp(argv[1], "intervall") == 0) { - if (argc > 2) { - iRet = Tcl_GetInt(pSics->pTcl, argv[2], &iVal); - if (iRet != TCL_OK) { - SCWrite(pCon, "ERROR: failed to convert new intervall to number", - eError); - return 0; - } - iIntervall = iVal; - } - SCPrintf(pCon, eValue, "%s.intervall [min] = %d", argv[0], iIntervall); - return 1; - } else if (strcmp(argv[1], "history") == 0) { - if (argc > 2) { - iRet = Tcl_GetInt(pSics->pTcl, argv[2], &iVal); - if (iRet != TCL_OK) { - SCWrite(pCon, "ERROR: failed to convert new history to number", - eError); - return 0; - } - writeHistory = iVal; - } - SCPrintf(pCon, eValue, "%s.writeHistory = %d", argv[0], writeHistory); - return 1; - } else if (strcmp(argv[1], "historyfilter") == 0) { - if (argc > 2) { - if(strlen(argv[2]) < 1024){ - strcpy(pHistoryFilter,argv[2]); - } else { - SCWrite(pCon,"ERROR: history filter to long", eError); - return 0; - } - SCSendOK(pCon); - return 1; - } - SCPrintf(pCon, eValue, "%s.historyFilter = %s", argv[0], pHistoryFilter); - return 1; - } else if (strcmp(argv[1], "compact") == 0) { - if (argc > 2) { - iCompact = atoi(argv[2]); - if (iCompact > 0) - iIntervall = 0; - } - SCPrintf(pCon, eValue, "%s.compact [sec] = %d", argv[0], (int)iCompact); - return 1; - } else if (strcmp(argv[1], "close") == 0) { /* close command */ - fclose(fd); - fd = NULL; - SCSendOK(pCon); - return 1; - } - snprintf(pBueffel, 1024,"ERROR: subcommand %s to commandlog unknown", argv[1]); - SCWrite(pCon, pBueffel, eError); - return 0; -} - -/*-------------------------------------------------------------------------*/ -void CommandLogClose(void *pData) -{ - if (fd) { - fclose(fd); - } - if (fauto) - fclose(fauto); - if (pData) - KillDummy(pData); - if (pTail) - deleteCircular(pTail); -} -/*-------------------------------------------------------------------------*/ -void CommandLogInit(void) -{ - AddCommand(pServ->pSics, "commandlog", CommandLog, CommandLogClose, NULL); -} -/*---------------------- History -----------------------------------------*/ -static FILE *comHistory = NULL; -/*-----------------------------------------------------------------------*/ -static int openHistoryLog() -{ - char *fileName = NULL; - char fileBuffer[1024]; - time_t iDate; - struct tm *psTime; - - - if (comHistory == NULL) { - fileName = IFindOption(pSICSOptions, "historylog"); - if (fileName != NULL) { - strlcpy(fileBuffer, fileName,1024); - } else { - iDate = time(NULL); - psTime = localtime(&iDate); - fileBuffer[0] = '\0'; - fileName = getenv("HOME"); - if (fileName != NULL) { - snprintf(fileBuffer, 1023, "%s/log/comhistory%4.4d.log", - fileName, psTime->tm_year + 1900); - } - } - comHistory = fopen(fileBuffer, "a+"); - } - if (comHistory == NULL) { - return 0; - } else { - return 1; - } -} -/*--------------------------------------------------------------------------- - * This is to suppress certain stuff from the history log in order to stop it - * from filling with garbage - -----------------------------------------------------------------------------*/ -static int historyFilter(char *command) -{ - static char *toRemove[] = {"sct", "hupdate","contextdo","transact", NULL}; - char token[50]; - char *pPtr = NULL; - int i = 0; - - while(toRemove[i] != NULL){ - if(strstr(command,toRemove[i]) != NULL){ - return 0; - } - i++; - } - - pPtr = pHistoryFilter; - while((pPtr = stptok(pPtr,token,50,":")) != NULL){ - if(strstr(command,token) != NULL){ - return 0; - } - } - - return 1; -} -/*-----------------------------------------------------------------------*/ -void WriteCommandHistory(char *txt) -{ - if(writeHistory == 0){ - return; - } - if(comHistory == NULL){ - openHistoryLog(); - } - if(comHistory != NULL){ - if(historyFilter(txt)){ - fprintf(comHistory,"%s\n", txt); - } - } -} -/*-----------------------------------------------------------------------*/ -void SetWriteHistory(int i) -{ - /* writeHistory = i;*/ - writeHistory = 0; -} diff --git a/commandlog.h b/commandlog.h deleted file mode 100644 index 82293f79..00000000 --- a/commandlog.h +++ /dev/null @@ -1,22 +0,0 @@ -/*-------------------------------------------------------------------------- - C O M M A N D L O G - - A much requested facility for writing only user an manager level commands - in a transcript file. This is it. - - Mark Koennecke, June 1998 - ---------------------------------------------------------------------------*/ -#ifndef COMMANDLOG -#define COMMANDLOG -void WriteToCommandLog(const char *prompt, const char *pText); -void WriteToCommandLogId(char *prompt, int id, char *text); -void WriteToCommandLogCmd(int id, char *text); -int CompactCommandLog(void); -int CommandLog(SConnection * pCon, SicsInterp * pSics, void *pData, - int argc, char *argv[]); - -void CommandLogClose(void *pData); -void WriteCommandHistory(char *txt); -void SetWriteHistory(int i); -#endif diff --git a/conman.c b/conman.c index 0046f3c0..37609650 100644 --- a/conman.c +++ b/conman.c @@ -62,13 +62,11 @@ #include "passwd.h" #include "splitter.h" #include "macro.h" -#include "servlog.h" #include "status.h" #include "interrupt.h" #include "ifile.h" #include "token.h" #include "uubuffer.h" -#include "commandlog.h" #include "stptok.h" #include "statusfile.h" #include "sicshipadaba.h" @@ -89,7 +87,7 @@ extern struct json_object *mkJSON_Object(SConnection * pCon, char *pBuffer, extern pServer pServ; -#include "outcode.c" /* text for OutCode */ +#include "outcode.h" /* text for OutCode */ int KillCapture(SConnection * pCon); @@ -158,9 +156,9 @@ char *ConID(SConnection *pCon) if(ANETvalidHandle(pCon->sockHandle)){ ANETinfo(pCon->sockHandle, host, sizeof(host)); - snprintf(id,sizeof(id),"%s:%2.2d", host, pCon->sockHandle); + snprintf(id,sizeof(id),"%s:sock%3.3d", host, pCon->sockHandle); } else { - snprintf(id,sizeof(id),"disconnected:%2.2ld", pCon->ident); + snprintf(id,sizeof(id),"disconnected:con%ld", pCon->ident); } return id; } @@ -200,7 +198,7 @@ static SConnection *SCMakeConnection() pRes = (SConnection *) malloc(sizeof(SConnection)); if (!pRes) { /* This is a serious, very serious error! */ - SICSLogWrite("ERROR: No memory to allocate connection!!", eInternal); + Log(ERROR,"sys","%s","No memory to allocate connection!!"); return NULL; } memset(pRes, 0, sizeof(SConnection)); @@ -223,8 +221,7 @@ static SConnection *CreateConnection(SicsInterp * pSics) used name */ if (lastIdent == LONG_MAX) { /* This is a serious, very serious error! */ - SICSLogWrite("ERROR: Run out of connection identifiers!!", - eInternal); + Log(FATAL,"sys""%s","Run out of connection identifiers!!"); return NULL; } lastIdent++; @@ -235,7 +232,7 @@ static SConnection *CreateConnection(SicsInterp * pSics) pRes->pDes = CreateDescriptor("Connection"); if (!pRes->pDes) { /* This is a serious, very serious error! */ - SICSLogWrite("ERROR: No memory to allocate connection!!", eInternal); + Log(ERROR,"sys","%s","No memory to allocate connection!!"); FreeConnection(pRes); return NULL; } @@ -247,7 +244,7 @@ static SConnection *CreateConnection(SicsInterp * pSics) pRes->pStack = CreateCommandStack(); if ((pRes->iList < 0) || (!pRes->pStack)) { /* This is a serious, very serious error! */ - SICSLogWrite("ERROR: No memory to allocate connection!!", eInternal); + Log(ERROR,"sys","%s","No memory to allocate connection!!"); DeleteDescriptor(pRes->pDes); FreeConnection(pRes); return NULL; @@ -310,7 +307,7 @@ SConnection *SCCreateDummyConnection(SicsInterp * pSics) pRes->iUserRights = usInternal; pRes->iGrab = 0; - SICSLogWrite("Accepted dummy connection ", eInternal); + Log(INFO,"SYS","%s","Accepted dummy connection "); return pRes; } @@ -319,11 +316,11 @@ SConnection *SCCreateDummyConnection(SicsInterp * pSics) int VerifyConnection(SConnection * self) { if (!self) { - SICSLogWrite("MAGICERROR: Invalid call to NULL connection", eError); + Log(ERROR,"sys","%s","MAGICERROR: Invalid call to NULL connection"); return 0; } if (self->lMagic != CONMAGIC) { - SICSLogWrite("MAGICERROR: corrupted connection object", eError); + Log(ERROR,"sys","%s","MAGICERROR: corrupted connection object"); return 0; } return 1; @@ -379,8 +376,7 @@ void SCDeleteMasterFields(SConnection * pVictim) if (SCActive(pVictim)) { SCnoSock(pVictim); ANETclose(pVictim->sockHandle); - WriteToCommandLog("SYS>", - "ERROR: Erraneous deletion of used Connection stopped"); + Log(ERROR,"sys","%s","Erraneous deletion of used Connection stopped"); pVictim->sockHandle = -1; return; } @@ -410,10 +406,9 @@ void SCDeleteMasterFields(SConnection * pVictim) /* log the kill */ if (pVictim->sockHandle >= 0 && pVictim->iLogin == 1 && - (pVictim->iUserRights < 3 || !CompactCommandLog())) { + pVictim->iUserRights < 3) { sprintf(pBueffel, "Deleting connection %d", pVictim->sockHandle); - WriteToCommandLog("SYS>", pBueffel); - SICSLogWrite(pBueffel, eInternal); + Log(DEBUG,"sys","%s", pBueffel); } /* close all open files and sockets */ @@ -660,9 +655,6 @@ int SCWrite(SConnection * self, char *pBuffer, int iOut) if (pBuffer == NULL) { return 0; } - if(!SCinMacro(self) || mustWrite(iOut) ){ - traceCommand(ConID(self),"out:%s", pBuffer); - } return self->write(self, pBuffer, iOut); } @@ -748,8 +740,8 @@ static int doSockWrite(SConnection * self, char *buffer) if (!iRet) { SCnoSock(self); if (!self->listening && self->iLogin == 1 && - (self->iUserRights < 3 || !CompactCommandLog())) { - WriteToCommandLog("SYS>", "Connection broken on send"); + self->iUserRights < 3) { + Log(ERROR,"sys","%s", "Connection broken on send"); } } } else { @@ -762,25 +754,6 @@ static int doSockWrite(SConnection * self, char *buffer) return iRet; } -/*--------------------------------------------------------------------------*/ -static void testAndWriteCommandLog(SConnection * pCon, char *buffer, - int iOut) -{ - if (SCGetRights(pCon) <= usUser) { - if (SCinMacro(pCon) != 1) { - SetSendingConnection(pCon); - WriteToCommandLogId(NULL, pCon->sockHandle, buffer); - SetSendingConnection(NULL); - } else { - if (iOut == eLog || iOut == eLogError) { - SetSendingConnection(pCon); - WriteToCommandLogId(NULL, pCon->sockHandle, buffer); - SetSendingConnection(NULL); - } - } - } -} - /*--------------------------------------------------------------------------*/ static void testAndStoreInTcl(SConnection * pCon, char *buffer, int iOut) { @@ -827,56 +800,69 @@ static int isOK(const char *buffer) return 1; return 0; } - /*--------------------------------------------------------------------------*/ -static void testAndWriteSICSLog(SConnection * self, char *buffer, int iOut) +static void testAndWriteLog(SConnection * self, char *buffer, int iOut) { - char tp; - /* We don't want to log the "OK" messages */ - if (isOK(buffer)) - return; - - if (SCinMacro(self)) { - tp = 'M'; - if (sicsdebug()) - tp = 'D'; - } else - tp = 'N'; - switch (iOut) { - case eStatus: - case eStart: - case eFinish: - case eEvent: - case eHdbValue: - case eHdbEvent: - case eLog: - case eLogError: - case eError: - case eWarning: - /* Log it */ - SICSLogWriteCode(buffer, iOut, tp); - return; - case eValue: - if (sicsdebug() || !SCinMacro(self)) { - /* Log it */ - SICSLogWriteCode(buffer, iOut, tp); - return; - } else { - /* Suppressed */ -#if 0 - tp = tolower(tp); - SICSLogWriteCode(buffer, iOut, tp); -#endif - return; + /* + first those which allways go into the log + */ + switch(iOut){ + case eInternal: + Log(ERROR,"sys","%s",buffer); + break; + case eCommand: + if(!SCinMacro(self)){ + Log(DEBUG,"sys","%s",buffer); } break; + case eHWError: + case eInError: + Log(ERROR,"dev","%s",buffer); + break; + case eStatus: + Log(DEBUG,"IO","%s",buffer); + break; + case eEvent: + if(strstr(buffer,"ERROR") != NULL){ + Log(ERROR,"notify",buffer); + }else if(strstr(buffer,"WARNING") != NULL) { + Log(WARN,"notify",buffer); + } else { + Log(INFO,"notify",buffer); + } + break; + case eHdbEvent: + case eHdbValue: + Log(INFO,"notify","%s",buffer); + break; + case eLog: + Log(INFO,"com","sock%03.3d:%s",self->sockHandle,buffer); + break; + case eLogError: + Log(ERROR,"com","sock%03.3d:%s",self->sockHandle,buffer); + break; + case eError: + if(!SCinMacro(self)){ + Log(ERROR,"com","sock%03.3d:%s",self->sockHandle,buffer); + } + break; + case eWarning: + if(!SCinMacro(self)){ + Log(WARN,"com","sock%03.3d:%s",self->sockHandle,buffer); + } + break; + case eValue: + if(!SCinMacro(self)){ + Log(INFO,"com","sock%03.3d:%s",self->sockHandle,buffer); + } + break; default: - printf("Unrecognized ouput code %d in testAndWriteSICSLog: FIXME!!!\n", iOut); - SICSLogWriteCode(buffer, iOut, tp); - return; + Log(DEBUG,"sys","Unknown outcode %d detected, FIXME ASAP!!!", iOut); } + } + /*--------------------------------------------------------------------------*/ int SCNormalWrite(SConnection * self, char *buffer, int iOut) { @@ -891,13 +877,7 @@ int SCNormalWrite(SConnection * self, char *buffer, int iOut) } /* log it for any case */ -#if 0 - SICSLogWrite(buffer, iOut); -#else - testAndWriteSICSLog(self, buffer, iOut); -#endif - - testAndWriteCommandLog(self, buffer, iOut); + testAndWriteLog(self, buffer, iOut); testAndStoreInTcl(self, buffer, iOut); @@ -918,10 +898,7 @@ int SCAllWrite(SConnection * self, char *buffer, int iOut) return 1; /* do not write empty line */ } - /* log it for any case */ - SICSLogWrite(buffer, iOut); - - testAndWriteCommandLog(self, buffer, iOut); + testAndWriteLog(self, buffer, iOut); testAndStoreInTcl(self, buffer, iOut); @@ -946,10 +923,7 @@ int SCACTWrite(SConnection * self, char *buffer, int iOut) } /* log it for any case */ - sprintf(pBueffel, "Next line intended for socket: %d", self->sockHandle); - SICSLogWrite(buffer, iOut); - - testAndWriteCommandLog(self, buffer, iOut); + testAndWriteLog(self, buffer, iOut); testAndStoreInTcl(self, buffer, iOut); @@ -986,11 +960,7 @@ int SCWriteWithOutcode(SConnection * self, char *buffer, int iOut) } /* log it for any case */ - sprintf(pBueffel, "Next line intended for socket: %d", self->sockHandle); - SICSLogWrite(pBueffel, eInternal); - SICSLogWrite(buffer, iOut); - - testAndWriteCommandLog(self, buffer, iOut); + testAndWriteLog(self, buffer, iOut); testAndStoreInTcl(self, buffer, iOut); /* @@ -999,8 +969,7 @@ int SCWriteWithOutcode(SConnection * self, char *buffer, int iOut) length = strlen(buffer) + strlen(pCode[iOut]) + 10; bufPtr = (char *) malloc(length * sizeof(char)); if (!bufPtr) { - SICSLogWrite("SYS>>ERROR: out of memory in SCWriteWithOutcode", - eError); + Log(ERROR,"sys","%s","out of memory in SCWriteWithOutcode"); return 0; } memset(bufPtr, 0, length * sizeof(char)); @@ -1078,9 +1047,7 @@ int SCOnlySockWrite(SConnection * self, char *buffer, int iOut) } /* log it for any case */ - sprintf(pBueffel, "Next line intended for socket: %d", self->sockHandle); - SICSLogWrite(pBueffel, eInternal); - SICSLogWrite(buffer, iOut); + testAndWriteLog(self,buffer,iOut); testAndStoreInTcl(self, buffer, iOut); @@ -1138,7 +1105,7 @@ int SCLogWrite(SConnection * self, char *buffer, int iOut) return 0; } SetSendingConnection(self); - WriteToCommandLogId(NULL, self->sockHandle, buffer); + Log(INFO,"com","sock%03.3d%s", self->sockHandle, buffer); SetSendingConnection(NULL); if(self->iProtocolID == PROTACT) { /* act */ @@ -1212,12 +1179,8 @@ int SCFileWrite(SConnection * self, char *buffer, int iOut) } /* log it for any case */ - sprintf(pBueffel, "Next line intended for socket: %d", self->sockHandle); - SICSLogWrite(pBueffel, eInternal); - SICSLogWrite(buffer, iOut); - - testAndWriteCommandLog(self, buffer, iOut); + testAndWriteLog(self, buffer, iOut); testAndStoreInTcl(self, buffer, iOut); @@ -1694,7 +1657,7 @@ int SCPrompt(SConnection * pCon, char *pPrompt, char *pResult, int iLen) if (iRet == 1) { CostaLock(master->pStack); strlcpy(pResult, pPtr, iLen); - WriteToCommandLogId(" prompted>", pCon->sockHandle, pPtr); + Log(INFO,"sys","prompted%03.3d:", pCon->sockHandle, pPtr); return 1; } } @@ -1739,7 +1702,7 @@ int SCPromptTMO(SConnection * pCon, char *pPrompt, char *pResult, int iLen, int if (iRet == 1) { CostaLock(master->pStack); strlcpy(pResult, pPtr, iLen); - WriteToCommandLogId(" prompted>", pCon->sockHandle, pPtr); + Log(INFO,"com"," prompted%03.3d:", pCon->sockHandle, pPtr); return 1; } } @@ -1840,10 +1803,10 @@ int SCInvoke(SConnection * self, SicsInterp * pInter, char *pCommand) SetSendingConnection(self); if (self->sockHandle >= 0) { if(strstr(pCommand,"Poch") == NULL){ - WriteToCommandLogCmd(self->sockHandle, pCommand); + Log(INFO,"com","sock%03.3d:",self->sockHandle, pCommand); } } else { - WriteToCommandLog("CRON>>", pCommand); + Log(INFO,"sys","CRON:%s", pCommand); } SetSendingConnection(NULL); } @@ -2004,19 +1967,9 @@ int ConfigCon(SConnection * pCon, SicsInterp * pSics, void *pData, SCWrite(pCon, pBueffel, eError); return 0; } - if (CompactCommandLog()) { - if (pCon->iUserRights < 3 || i < 3) { - ANETinfo(pCon->sockHandle, pHost, sizeof pHost); - snprintf(pBueffel, sizeof pBueffel, - "User %s from %s switched to %d privilege", - argv[2], pHost, i); - WriteToCommandLogId("SYS>", pCon->sockHandle, pBueffel); - } - } else { - snprintf(pBueffel, 511, "User %s handle %d switched to %d privilege", + snprintf(pBueffel, 511, "User %s handle %d switched to %d privilege", argv[2], pCon->sockHandle, i); - WriteToCommandLog("SYS>", pBueffel); - } + Log(INFO,"sys","%s", pBueffel); pCon->iUserRights = i; pMaster->iUserRights = i; SCWrite(pCon, "Change of Authorisation Acknowledged", eWarning); @@ -2279,114 +2232,9 @@ static void hookFunc(const char *pText, OutCode eOut, void*pData) int KillCapture(SConnection * pCon) { - RemSICSLogHook(pCon); return 1; } - -/* ------------------------------------------------------------------------ - the command function: - Syntax: - Kill kills all logging - Log OutCode starts loggin OutCode events - All starts logging all events --------------------------------------------------------------------------- */ - -int LogCapture(SConnection * pCon, SicsInterp * pSics, void *pData, - int argc, char *argv[]) -{ - SConnection * pConMaster; - char pBueffel[512]; - int i; - - pConMaster = SCfindMaster(pCon); - if (pConMaster == NULL) - return 0; - /* check no af args */ - if (argc < 2) { - snprintf(pBueffel,sizeof(pBueffel)-1, "Insufficient number of arguments to %s", argv[0]); - SCWrite(pCon, pBueffel, eError); - return 0; - } - argtolower(argc, argv); - - /* Branch according to argv[1] */ - if (strcmp(argv[1], "kill") == 0 || strcmp(argv[1], "none") == 0) { - SCPrintf(pCon, eLog, "getlog %s", argv[1]); - KillCapture(pConMaster); - return 1; - } else if (strcmp(argv[1], "what") == 0) { - unsigned int code_bits = 0; - pDynString buffer; - code_bits = (1 << iNoCodes) - 1; - buffer = CreateDynString(100, 100); - for (i = 0; i < iNoCodes; ++i) { - if (code_bits & (1 << i)) { - if (GetDynStringLength(buffer) > 0) - DynStringConcatChar(buffer, ','); - DynStringConcat(buffer, (char *)OutCodeToTxt(i)); - } - } - SCPrintf(pCon, eLog, "getlog %s", GetCharArray(buffer)); - DeleteDynString(buffer); - return 1; - } else if (strcmp(argv[1], "list") == 0) { - unsigned int code_bits = 0; - pDynString buffer; - code_bits = GetSICSLogHook(pConMaster); - if (code_bits == 0) { - SCPrintf(pCon, eLog, "getlog none"); - return 1; - } - buffer = CreateDynString(100, 100); - for (i = 0; i < iNoCodes; ++i) { - if (code_bits & (1 << i)) { - if (GetDynStringLength(buffer) > 0) - DynStringConcatChar(buffer, ','); - DynStringConcat(buffer, (char *)OutCodeToTxt(i)); - } - } - SCPrintf(pCon, eLog, "getlog %s", GetCharArray(buffer)); - DeleteDynString(buffer); - return 1; - } else if (strcmp(argv[1], "all") == 0) { - SCPrintf(pCon, eLog, "getlog all"); - AddSICSLogHook(hookFunc, "all", pConMaster); - return 1; - } else if (argc == 2) { - /* must be outcode, try find it */ - SCPrintf(pCon, eLog, "getlog %s", argv[1]); - AddSICSLogHook(hookFunc, argv[1], pConMaster); - return 1; - } else { - /* make it a list */ - int i; - size_t len; - char *pBuff; - for (i = 1, len = 0; i < argc; ++i) - len += strlen(argv[i]) + 1; - if (len > sizeof(pBueffel)) - pBuff = malloc(len); - else - pBuff = pBueffel; - if (pBuff == NULL) { - SCWrite(pCon, "Out of memory in LogCapture\n", eError); - return 1; - } - for (i = 1, len = 0; i < argc; ++i) { - if (i > 1) - pBuff[len++] = ','; - strcpy(&pBuff[len], argv[i]); - len += strlen(argv[i]); - } - SCPrintf(pCon, eLog, "getlog %s", pBuff); - AddSICSLogHook(hookFunc, pBuff, pConMaster); - if (pBuff != pBueffel) - free(pBuff); - return 1; - } - return 0; -} /* ------------------------------------------------------------------------ the command function: Syntax: @@ -2437,7 +2285,7 @@ int LogOutput(SConnection * pCon, SicsInterp * pSics, void *pData, strcpy(&pBuff[len], argv[i]); len += strlen(argv[i]); } - SICSLogWrite(pBuff, outcode); + Log(INFO,"com","%s",pBuff); if (pBuff != pBueffel) free(pBuff); return 1; @@ -2516,22 +2364,11 @@ int SCTaskFunction(void *pData) self->iLogin = 1; SCSetRights(self, iRet); pHost[0] = '\0'; - if (CompactCommandLog()) { - if (iRet < 3) { - ANETinfo(self->sockHandle, pHost, 131); - sprintf(pBueffel, "Accepted connection %s from %s as %s", - ConName(self->ident), pHost, pUser); - SICSLogWrite(pBueffel, eInternal); - WriteToCommandLogId("SYS>", self->sockHandle, pBueffel); - } - } else { - ANETinfo(self->sockHandle, pHost, 131); - snprintf(pBueffel, 511, + ANETinfo(self->sockHandle, pHost, 131); + snprintf(pBueffel, 511, "Accepted connection %s on socket %d from %s", ConName(self->ident), self->sockHandle, pHost); - SICSLogWrite(pBueffel, eInternal); - WriteToCommandLog("SYS >", pBueffel); - } + Log(INFO,"sys","%s",pBueffel); free(pPtr); return 1; } else { diff --git a/counter.c b/counter.c index d01de97c..72c8aeac 100644 --- a/counter.c +++ b/counter.c @@ -747,7 +747,7 @@ int CounterInterest(int iEvent, void *pEvent, void *pUser) * prevent this to be written to log files */ SCSetRights(pCon, usSpy); - SCWrite(pCon, pBueffel, eLog); + SCWrite(pCon, pBueffel, eEvent); return 1; } /*------------------------------------------------------------------------*/ diff --git a/danu.c b/danu.c index f19410e8..2fbce6d0 100644 --- a/danu.c +++ b/danu.c @@ -122,7 +122,7 @@ static int InterestCallback(int iEvent, void *pEvent, void *pUser) iNum = readDataNumber(self); if (iNum > 0) { snprintf(pBueffel, 131, "sicsdatanumber = %d", iNum); - SCWrite(pCon, pBueffel, eValue); + SCWrite(pCon, pBueffel, eEvent); } return 1; } diff --git a/devexec.c b/devexec.c index 8fd81cea..dcea95e0 100644 --- a/devexec.c +++ b/devexec.c @@ -67,7 +67,6 @@ #include "devexec.h" #include "status.h" #include "lld.h" -#include "commandlog.h" #include "ifile.h" /* diff --git a/evcontroller.c b/evcontroller.c index f1120b5c..e5542976 100644 --- a/evcontroller.c +++ b/evcontroller.c @@ -66,7 +66,6 @@ #include "chadapter.h" #include "status.h" #include "site.h" -#include "commandlog.h" /*--------------------- Functions needed to implement interfaces -----------*/ static long EVIDrive(void *pData, SConnection * pCon, float fVal) { @@ -607,7 +606,7 @@ static int EVIIsInTolerance(void *pData) */ memset(pError, 0, 132 * sizeof(char)); self->pDriv->GetError(self->pDriv, &iCode, pError, 131); - WriteToCommandLog("emon>> ", pError); + Log(ERROR,"dev", "emon:%s", pError); iStat = self->pDriv->TryFixIt(self->pDriv, iCode); if ((iStat == DEVOK) || (iStat == DEVREDO)) { return 1; /* effectively a redo in some time */ diff --git a/exebuf.c b/exebuf.c index aefa8b7c..e76855cf 100644 --- a/exebuf.c +++ b/exebuf.c @@ -18,7 +18,6 @@ #include "dynstring.h" #include "exebuf.i" #include "status.h" -#include "commandlog.h" char *ConID(SConnection *pCon); /* in conman.c */ diff --git a/exeman.c b/exeman.c index 55ae402a..359a990d 100644 --- a/exeman.c +++ b/exeman.c @@ -24,7 +24,6 @@ #include "exeman.i" #include "exeman.h" #include "sicshipadaba.h" -#include "commandlog.h" #include "protocol.h" /*-------------------------------------------------------------------*/ static void KillExeMan(void *data) @@ -320,8 +319,7 @@ static int SCHdbWrite(SConnection * self, char *message, int outCode) v.dataType = HIPTEXT; val = CreateDynString(128, 128); if (val == NULL) { - WriteToCommandLog("INTERNAL ERROR>>", - "No memory to append to log in SCHdbWrite"); + Log(ERROR,"sys","%s", "No memory to append to log in SCHdbWrite"); return 0; } if (v.v.text != NULL) { diff --git a/histmem.c b/histmem.c index 8e106428..e7923999 100644 --- a/histmem.c +++ b/histmem.c @@ -996,11 +996,11 @@ static int HMCountInterest(int iEvent, void *pEvent, void *pUser) if (iEvent == COUNTSTART && pUser != NULL) { pCon = (SConnection *) pUser; assert(pCon); - SCWrite(pCon, "HMCOUNTSTART", eWarning); + SCWrite(pCon, "HMCOUNTSTART", eEvent); return 1; } else if (iEvent == COUNTEND) { assert(pCon); - SCWrite(pCon, "HMCOUNTEND", eWarning); + SCWrite(pCon, "HMCOUNTEND", eEvent); return 1; } return 0; diff --git a/intserv.c b/intserv.c index e0a92e0f..1e9c7d20 100644 --- a/intserv.c +++ b/intserv.c @@ -33,7 +33,6 @@ #include "splitter.h" #include "configfu.h" #include "devexec.h" -#include "servlog.h" #include "nread.h" #include "task.h" #include "event.h" diff --git a/logv2.c b/logv2.c index 93cc567d..cc10b6c4 100644 --- a/logv2.c +++ b/logv2.c @@ -24,9 +24,11 @@ static unsigned int MAXFILELINES = 100000; static unsigned int lineCount = 0; static char logTemplate[1024]; static char logFilename[1024]; +static unsigned int logDisabled = 0; +static int unsigned logConfigured = 0; /*================ The default log level =======================================*/ -static unsigned int globalLogLevel = 7; +static unsigned int globalLogLevel = 4; /*========= The list of sub systems for which full logging is enabled ==========*/ static int subList; /*================== Callback management =======================================*/ @@ -79,7 +81,7 @@ static char *makeLogFileName(void) return filename; } /*----------------------------------------------------------------------------*/ -static void LogClose(void *data) +void LogClose(void *data) { if(logFile != NULL){ fclose(logFile); @@ -93,6 +95,10 @@ static void checkLogFile(void) { char *filename = NULL; + if(logDisabled || logConfigured == 0){ + return; + } + /* close when full */ @@ -116,11 +122,21 @@ static void checkLogFile(void) static void writeLog(char *logMessage) { int nChar; + unsigned int end; + char *pPtr; + const char delim = '\n'; if(logMessage == NULL){ return; } + /* + remove a trailing newline + */ + end = strlen(logMessage); + if(logMessage[end-1] == delim){ + logMessage[end-1] = '\0'; + } if(logFile != NULL){ nChar = fprintf(logFile,"%s\n",logMessage); @@ -134,6 +150,11 @@ static unsigned int logFilter(unsigned int severity, const char *subsystem) int status; char buffer[1024]; + if(logDisabled || logConfigured == 0){ + return 1; + } + + /* If it is in the list of enabled subsystems, everything is logged */ @@ -146,12 +167,14 @@ static unsigned int logFilter(unsigned int severity, const char *subsystem) status = LLDnodePtr2Next(subList); } + /* test against the global log level */ - if(severity >= globalLogLevel){ + if(severity > globalLogLevel){ return 1; } + return 0; } /*=============================================================================*/ @@ -246,7 +269,7 @@ void Log(unsigned int severity, const char *subsystem,const char *format,...) { char severityTXT[60]; char timeStamp[132]; - char logData[2024], logLine[3072]; + char logData[2024], logLine[3072], *pPtr = NULL; char *dynMessage = NULL, *logMessage, *fullMessage = NULL; va_list ap; int dataLength; @@ -415,6 +438,7 @@ static int LogConfigAction(SConnection * pCon, SicsInterp * pSics, } else if(strcmp(argv[1],"logtemplate") == 0){ if(argc > 2){ strncpy(logTemplate,argv[2],sizeof(logTemplate)); + logConfigured = 1; SCSendOK(pCon); } else { SCPrintf(pCon,eValue,"logconfig.logtemplate = %s", logTemplate); @@ -474,6 +498,11 @@ static int LogConfigAction(SConnection * pCon, SicsInterp * pSics, return 1; } /*-----------------------------------------------------------------------------*/ +void DisableLog(void) +{ + logDisabled = 1; +} +/*-----------------------------------------------------------------------------*/ void Logv2Init(void) { subList = LLDstringCreate(); diff --git a/logv2.h b/logv2.h index f8779bf6..5029e6fc 100644 --- a/logv2.h +++ b/logv2.h @@ -57,4 +57,13 @@ typedef void (*LogCallback)(unsigned int severity, const char *timeStamp, void RegisterLogCallback(LogCallback func, void *userData); void RemoveLogCallback(LogCallback func); +/* + *Disable logging in support of the nolog option in SICSmain.c + */ +void DisableLog(void); +/* + * close the log as cleanup on exit + */ +void LogClose(void *data); + #endif diff --git a/macro.c b/macro.c index d7b39ad1..a27a84fc 100644 --- a/macro.c +++ b/macro.c @@ -67,12 +67,10 @@ #include "splitter.h" #include "ifile.h" #include "Dbg.h" -#include "servlog.h" #include "sicsglobal.h" #include "stringdict.h" #include "exeman.h" #include "nxcopy.h" -#include "commandlog.h" #define SICSERROR "005567SICS" /*---------------------------------------------------------------------------- @@ -193,7 +191,14 @@ static int SicsUnknownProc(ClientData pData, Tcl_Interp * pInter, /* finish */ if (iRet == 1) { - WriteCommandHistory(comBuffer); + Arg2Text(argc-1,&argv[1],comBuffer,sizeof(comBuffer)); + /* + suppress the sct commands: there is no point in having them in + the history + if(strstr(argv[1],"sct") == NULL){ + Log(DEBUG,"history","%s",comBuffer); + } + */ return TCL_OK; } else { Tcl_SetVar(pInter, SICSERROR, "yes", TCL_GLOBAL_ONLY); @@ -476,8 +481,7 @@ int MacroFileEval(SConnection * pCon, SicsInterp * pInter, void *pData, /* handle status first */ - SICSLogWrite("Evaluating in MacroFileEval", eValue); - SICSLogWrite(argv[1], eValue); + Log(INFO,"com","Evaluating %s in MacroFileEval", argv[1]); if (pFile) { free(pFile); } @@ -604,7 +608,7 @@ int InternalFileEval(SConnection * pCon, SicsInterp * pInter, void *pData, The output code is optional and and defaults to eStatus. ---------------------------------------------------------------------------*/ -#include "outcode.c" +#include "outcode.h" int ClientPut(SConnection * pCon, SicsInterp * pInter, void *pData, int argc, char *argv[]) @@ -702,6 +706,17 @@ int ClientPut(SConnection * pCon, SicsInterp * pInter, void *pData, memset(pMessage, 0, (iLen + 100) * sizeof(char)); Arg2Text(iCode - 1, &argv[1], pMessage, (iLen + 100) * sizeof(char)); + /* + as the outcode is optional we have to test the message in order to get + proper outcodes for the log + */ + if(strstr(pMessage,"ERROR") != NULL){ + eOut = eLogError; + } + if(strstr(pMessage,"WARNING") != NULL){ + eOut = eWarning; + } + SCWrite(pCon, pMessage, eOut); if (pMessage) { free(pMessage); @@ -975,9 +990,7 @@ static int TclAction(SConnection * pCon, SicsInterp * pSics, void *pData, return 0; } Tcl_ResetResult(pTcl); - SetWriteHistory(0); iRet = Tcl_Eval(pTcl, pCommand); - SetWriteHistory(1); if (iRet == TCL_OK) { if (strlen(pTcl->result) > 0) { SCPrintf(pCon, eValue, "%s", pTcl->result); diff --git a/make_gen b/make_gen index b69e32c9..7abeb42d 100644 --- a/make_gen +++ b/make_gen @@ -10,7 +10,7 @@ EPICSOBJ= COBJ = Sclient.o network.o ifile.o intcli.o $(FORTIFYOBJ) SOBJ = network.o ifile.o conman.o SCinter.o splitter.o passwd.o \ - servlog.o sicvar.o nserver.o SICSmain.o motorlist.o\ + sicvar.o nserver.o SICSmain.o motorlist.o\ sicsexit.o costa.o task.o $(FORTIFYOBJ) testprot.o\ macro.o ofac.o obpar.o obdes.o drive.o status.o intserv.o \ devexec.o mumo.o mumoconf.o selector.o selvar.o fupa.o lld.o \ @@ -21,7 +21,7 @@ SOBJ = network.o ifile.o conman.o SCinter.o splitter.o passwd.o \ danu.o nxdict.o varlog.o stptok.o nread.o trigd.o cell.o\ scan.o fitcenter.o telnet.o token.o wwildcard.o hklmot.o\ tclev.o hkl.o integrate.o optimise.o dynstring.o nxutil.o \ - uubuffer.o commandlog.o udpquieck.o fourtable.o\ + uubuffer.o udpquieck.o fourtable.o\ rmtrail.o help.o nxupdate.o confvirtualmot.o vector.o\ simchop.o choco.o chadapter.o trim.o scaldate.o tasub.o\ xytable.o exebuf.o exeman.o ubfour.o ubcalc.o\ @@ -47,7 +47,7 @@ SOBJ = network.o ifile.o conman.o SCinter.o splitter.o passwd.o \ histmemsec.o sansbc.o sicsutil.o strlutil.o genbinprot.o trace.o\ singlebinb.o taskobj.o sctcomtask.o tasmono.o multicountersec.o \ messagepipe.o sicsget.o remoteobject.o pmacprot.o charbychar.o binprot.o \ - cnvrt.o tclClock.o tclDate.o tclUnixTime.o stack_trace.o logv2.o + cnvrt.o tclClock.o tclDate.o tclUnixTime.o stack_trace.o logv2.o outcode.o MOTOROBJ = motor.o simdriv.o COUNTEROBJ = countdriv.o simcter.o counter.o diff --git a/maximize.c b/maximize.c index 8be3b4ec..f74e1bf6 100644 --- a/maximize.c +++ b/maximize.c @@ -50,7 +50,6 @@ #include "motor.h" #define MAXPTS 100 -#define DEBUG 0 typedef struct __MAXIMIZE { pObjectDescriptor pDes; diff --git a/motor.c b/motor.c index 458614f0..76ec8b00 100644 --- a/motor.c +++ b/motor.c @@ -56,7 +56,6 @@ #include "motor.h" #include "splitter.h" #include "status.h" -#include "servlog.h" #include "tclmotdriv.h" #include "site.h" /*------------------------------------------------------------------------- diff --git a/network.c b/network.c index 944ecacf..b77e382a 100644 --- a/network.c +++ b/network.c @@ -52,7 +52,6 @@ #include #include #include "sics.h" -#include "commandlog.h" #include "uselect.h" #define PORT 1 @@ -69,10 +68,14 @@ struct timeval lastclose = { -1, 0 }; */ static void NetError(const char pText[]) { -/* - SICSLogWrite(pText,eError); -*/ - WriteToCommandLog("NET>", pText); + unsigned int severity = DEBUG; + if(strstr(pText,"ERROR") != NULL){ + severity = ERROR; + } else if(strstr(pText,"WARNING") != NULL){ + severity = WARN; + } + + Log(severity,"IO","%s", pText); } /* ---------------------------- Local ------------------------------------ diff --git a/nread.c b/nread.c index 476ab22f..2b68f8a5 100644 --- a/nread.c +++ b/nread.c @@ -29,7 +29,6 @@ #include "passwd.h" #include "conman.h" #include "SCinter.h" -#include "servlog.h" #include "costa.h" #include "task.h" #include "emon.h" @@ -39,7 +38,6 @@ #include "interrupt.h" #include "telnet.h" #include "nread.h" -#include "commandlog.h" #include "uselect.h" #include "trace.h" #include "protocol.h" @@ -163,7 +161,7 @@ int NetReadRegister(pNetRead self, mkChannel * pSock, eNRType eType, if (sEntry.pSock->sockid == pSock->sockid) { snprintf(buffer, sizeof buffer, "NetReadRegister twice %d type %d", pSock->sockid, eType); - WriteToCommandLog("SYS>", buffer); + Log(ERROR,"sys", buffer); return 1; } iRet = LLDnodePtr2Next(self->iList); @@ -219,7 +217,7 @@ static int NetReadAccept(pNetRead self, mkChannel * pSock) pRes = SCreateConnection(self->pMain->pSics,pNew,3); */ if (!pRes) { - SICSLogWrite("Failure to allocate new Connection", eInternal); + Log(ERROR,"sys","%s","Failure to allocate new Connection"); NETClosePort(pNew); free(pNew); return 0; @@ -266,9 +264,7 @@ static int NetReadRead(pNetRead self, pNetItem pItem) if (SCMatchRights(pItem->pCon, usUser)) { traceCommand(ConID(pItem->pCon),"interrupt: %d",iInt); TaskSignal(self->pMain->pTasker, SICSINT, &iInt); - snprintf(pBueffel,sizeof(pBueffel)-1, "INTERRUPT %d issued on sock %d", - iInt, pItem->pCon->pSock->sockid); - WriteToCommandLog("SYS>", pBueffel); + Log(ERROR,"com","sock%03.3d:INTERRUPT", pItem->pCon->pSock->sockid); if (iInt == eEndServer) { TaskStop(self->pMain->pTasker); } @@ -363,7 +359,7 @@ static int TelnetAccept(pNetRead self, mkChannel * pSock) pRes = SCreateConnection(self->pMain->pSics,pNew,usSpy); */ if (!pRes) { - SICSLogWrite("Failure to allocate new Connection", eInternal); + Log(ERROR,"sys","%s","Failure to allocate new Connection"); NETClosePort(pNew); free(pNew); return 0; @@ -371,8 +367,7 @@ static int TelnetAccept(pNetRead self, mkChannel * pSock) /* Create a task object for the telnet connection */ pTel = CreateTelnet(pRes); if (!pTel) { - SICSLogWrite("Failure to allocate new Telnet Task Object", - eInternal); + Log(ERROR,"sys","%s","Failure to allocate new Telnet Task Object"); SCDeleteConnection(pRes); return 0; } @@ -467,9 +462,6 @@ static int TelnetRead(pNetRead self, pNetItem pItem) } TaskSignal(self->pMain->pTasker, SICSINT, &iInt); traceCommand(ConID(pItem->pCon),"interrupt: %d",iInt); - snprintf(pError,sizeof(pError)-1, "INTERRUPT %d issued on sock %d", iInt, - pItem->pCon->pSock->sockid); - WriteToCommandLog("SYS>", pError); if (iInt == eEndServer) { TaskStop(self->pMain->pTasker); } @@ -627,7 +619,7 @@ static int TelnetRead(pNetRead self, pNetItem pItem) default: /* There is something wrong here! */ snprintf(pError,sizeof(pError)-1, "ERROR: bad telnet code %d", cChar); - SICSLogWrite(pError, eInternal); + Log(ERROR,"sys","%s",pError); pItem->tStatus = tData; break; @@ -706,15 +698,15 @@ int NetReaderTask(void *pData) } conCount++; if (conCount > 100) { - WriteToCommandLog("WAYTOMANYCONNECTIONS> ", + Log(ERROR,"sys","%s","WAYTOMANYCONNECTIONS:%s ", GetCharArray(self->conList)); } iRet = LLDnodePtr2Next(self->iList); } if (conCount > 100) { - WriteToCommandLog("WAYTOMANYCONNECTIONS> ", - GetCharArray(self->conList)); + Log(ERROR,"sys","%s","WAYTOMANYCONNECTIONS:%s ", + GetCharArray(self->conList)); } /* @@ -1043,8 +1035,6 @@ static int testAndInvokeInterrupt(pCommandCBData self, int handle) TaskSignal(pServ->pTasker, SICSINT, &iInt); snprintf(buffer, 512, "INTERRUPT %d issued on sock %d", iInt, handle); - WriteToCommandLog("SYS>", buffer); - SICSLogWrite(buffer, eInternal); if (iInt == eEndServer) { TaskStop(pServ->pTasker); } @@ -1115,12 +1105,12 @@ static int CommandAcceptCB(int handle, void *userData) pCon = SCreateConnection(pServ->pSics, handle, 3); usData = malloc(sizeof(CommandCBData)); if (pCon == NULL || usData == NULL) { - SICSLogWrite("Failure to allocate new Connection", eInternal); + Log(ERROR,"sys","%s","Failure to allocate new Connection"); return 0; } usData->command = CreateDynString(256, 256); if (usData->command == NULL) { - SICSLogWrite("Failure to allocate new Connection", eInternal); + Log(ERROR,"sys","%s","Failure to allocate new Connection"); return 0; } usData->pCon = pCon; @@ -1301,8 +1291,7 @@ static int ANETTelnetProcess(int handle, void *usData) default: /* There is something wrong here! */ - snprintf(pError,sizeof(pError)-1, "ERROR: bad telnet code %d", cChar); - SICSLogWrite(pError, eInternal); + Log(ERROR,"sys","Bad telnet code %d", cChar); self->state = tData; break; @@ -1323,12 +1312,12 @@ static int TelnetAcceptCB(int handle, void *userData) pCon = SCreateConnection(pServ->pSics, handle, 3); usData = malloc(sizeof(CommandCBData)); if (pCon == NULL || usData == NULL) { - SICSLogWrite("Failure to allocate new Connection", eInternal); + Log(ERROR,"sys","%s","Failure to allocate new Connection"); return 0; } usData->command = CreateDynString(256, 256); if (usData->command == NULL) { - SICSLogWrite("Failure to allocate new Connection", eInternal); + Log(ERROR,"sys","%s","Failure to allocate new Connection"); return 0; } usData->pCon = pCon; @@ -1336,7 +1325,7 @@ static int TelnetAcceptCB(int handle, void *userData) /* Create a task object for the telnet connection */ pTel = CreateTelnet(pCon); if (!pTel) { - SICSLogWrite("Failure to allocate new Telnet Task Object", eInternal); + Log(ERROR,"sys","%s","Failure to allocate new Telnet Task Object"); SCDeleteConnection(pCon); return 0; } @@ -1356,7 +1345,6 @@ static int TelnetAcceptCB(int handle, void *userData) static void NREADlog(int level, char *txt, void *userData) { traceSys("anet","%s",txt); - SICSLogWrite(txt, (level == ANETERROR) ? eLogError : eLog); } /*------------------------------------------------------------------------------------*/ diff --git a/nserver.c b/nserver.c index 5e2b0fcf..6d004c29 100644 --- a/nserver.c +++ b/nserver.c @@ -37,7 +37,6 @@ #include "tcldrivable.h" #include "nserver.h" #include "sicshipadaba.h" -#include "commandlog.h" extern int openDevexecLog(); /* in devexec.c */ @@ -49,6 +48,7 @@ static void StopExit(void) if (pServ) { StopServer(pServ); } + LogClose(NULL); } #define DEFAULTINIFILE "servo.tcl" @@ -124,7 +124,6 @@ int InitServer(char *file, pServer * pServ) TaskRegisterN(self->pTasker, "nwatch", NetWatchTask, NULL, NULL, NULL, TASK_PRIO_HIGH); /* initialise the server from script */ - SetWriteHistory(0); if (file == NULL) { iRet = InitObjectCommands(self, DEFAULTINIFILE); } else { @@ -265,7 +264,6 @@ int InitServer(char *file, pServer * pServ) strcpy(pBueffel, "restore"); SCInvoke(self->dummyCon, self->pSics, pBueffel); } - SetWriteHistory(1); INIT(StatusFileInit); @@ -376,6 +374,7 @@ void StopServer(pServer self) free(self); + LogClose(NULL); } /*------------------------------------------------------------------------*/ diff --git a/nxscript.c b/nxscript.c index 242ca32d..d624fdd1 100644 --- a/nxscript.c +++ b/nxscript.c @@ -188,6 +188,7 @@ static int handleFileOperations(SConnection * pCon, pNXScript self, self->fileHandle = NULL; self->dictHandle = NULL; SendQuieck(QUIECK, buffer); + traceIO("datafile", "Closing datafile"); SCSendOK(pCon); return 1; } else if (strcmp(argv[1], "reopen") == 0) { @@ -215,6 +216,7 @@ static int handleFileOperations(SConnection * pCon, pNXScript self, if (self->fileHandle != NULL) { NXclose(&self->fileHandle); self->fileHandle = NULL; + traceIO("datafile", "Closing datafile"); } if (self->dictHandle != NULL) { NXDclose(self->dictHandle, NULL); diff --git a/obdes.c b/obdes.c index ce0b9bb6..54130cb9 100644 --- a/obdes.c +++ b/obdes.c @@ -43,9 +43,8 @@ #include "fortify.h" #include "obdes.h" #include "conman.h" -#include "servlog.h" #include "hipadaba.h" - +#include "logv2.h" /*-------------------------------------------------------------------------*/ static void *DefaultGetInterface(void *pData, int iID) { @@ -102,14 +101,14 @@ pDummy CreateDummy(char *name) pRes = (pDummy) malloc(sizeof(Dummy)); if (!pRes) { - SICSLogWrite("Out of Memory in CreateDummy", eInternal); + Log(ERROR,"sys","Out of Memory in CreateDummy"); return NULL; } pRes->pDescriptor = CreateDescriptor(name); if (!pRes->pDescriptor) { free(pRes); - SICSLogWrite("Out of Memory in CreateDummy", eInternal); + Log(ERROR,"sys","%s","Out of Memory in CreateDummy"); return NULL; } return pRes; diff --git a/ofac.c b/ofac.c index e6bcdec5..df88921e 100644 --- a/ofac.c +++ b/ofac.c @@ -43,7 +43,6 @@ static void InitGeneral(void) INIT(LogSetupInit); INIT(InstallBackground); INIT(MakeProtocol); - INIT(CommandLogInit); INIT(UdpInit); INIT(HelpInit); INIT(AddTestProt); @@ -92,7 +91,6 @@ static void InitIniCommands(SicsInterp * pInter) PCMD("findalias", LocateAliasAction); PCMD("fulltransact", TransactAction); PCMD("GetInt", GetSICSInterrupt); - PCMD("GetLog", LogCapture); PCMD("GumPut", GumPut); PCMD("InternEval", InternalFileEval); PCMD("kill_command", SICSKill); diff --git a/oscillate.c b/oscillate.c index 19bc8e1d..5034d6b7 100644 --- a/oscillate.c +++ b/oscillate.c @@ -15,7 +15,6 @@ #include "fortify.h" #include "sics.h" #include "task.h" -#include "commandlog.h" #include "oscillate.h" #define ABS(x) (x < 0 ? -(x) : (x)) @@ -31,7 +30,7 @@ static void StopOscillation(pOscillator self) } MotorSetPar(self->pMot, self->pCon, "accesscode", usUser); if (self->debug > 0) { - WriteToCommandLog("oscillator>> ", "Stopping"); + Log(INFO,"com","%s","oscillator stopping"); } } @@ -79,16 +78,16 @@ static int OscillationTask(void *data) switch (status) { case HWFault: case HWPosFault: - WriteToCommandLog("oscillator>> ", + Log(ERROR,"com","%s:%s","oscillator:", "ERROR occurred in oscillation, try running motor manually to find out more"); - WriteToCommandLog("oscillator>> ", + Log(INFO,"com","%s:%s","oscillator", "Trying to run other direction"); pos = getNextPos(self); status = MotorRun(self->pMot, self->pCon, pos); if (self->debug > 0) { snprintf(message, 131, "Started oscillation to %f, ret code = %d", pos, status); - WriteToCommandLog("oscillator>>", message); + Log(INFO,"com","%s:%s","oscillator", message); } break; case HWWarn: @@ -109,7 +108,7 @@ static int OscillationTask(void *data) if (self->debug > 0) { snprintf(message, 131, "Started oscillation to %f, ret code = %d", pos, status); - WriteToCommandLog("oscillator>>", message); + Log(INFO,"com","%s:%s","oscillator", message); } } return 1; diff --git a/outcode.c b/outcode.c index 7b7f8f77..ab15f912 100644 --- a/outcode.c +++ b/outcode.c @@ -5,26 +5,41 @@ Mark Koennecke, November 1996 ----------------------------------------------------------------------------*/ -#ifndef POUTCODE -#define POUTCODE +#include "Scommon.h" +#include "outcode.h" +#include -static char *pCode[] = { - "internal", - "command", - "hwerror", - "inerror", - "status", - "value", - "start", - "finish", - "event", - "warning", - "error", - "hdbvalue", - "hdbevent", - "log", - "logerror", - NULL -}; -static int iNoCodes = 15; -#endif +const char* OutCodeToTxt(OutCode eOut) +{ + switch (eOut) { + case eInternal: return "Int"; /* internal */ + case eCommand: return "Cmd"; /* reserved, not used */ + case eHWError: return "ErH"; /* reserved, used only for SICSLog */ + case eInError: return "ErI"; /* reserved, used as a mark in the handling of output codes */ + case eStatus: return "Sta"; /* reserved, deprecated */ + case eValue: return "Val"; /* value reponse: copied into Tcl */ + case eStart: return "Beg"; /* start message */ + case eFinish: return "End"; /* finish message */ + case eEvent: return "Evt"; /* some callback messages */ + case eWarning: return "Wrn"; /* warnings */ + case eError: return "Err"; /* error: copied into Tcl */ + case eHdbValue: return "HVa"; /* hipadaba value chnage */ + case eHdbEvent: return "HEv"; /* Hipadaba event */ + case eLog: return "Log"; /* log message: is always written to client */ + case eLogError: return "ErL"; /* error message to log: is always written to client */ + } + return "???"; +} + +int OutCodeFromText(const char *text, OutCode *outcode) +{ + int i; + for (i = 0; i < iNoCodes; ++i) { + if (strcasecmp(text, pCode[i]) == 0) { + if (outcode) + *outcode = i; + return i; + } + } + return -1; +} diff --git a/outcode.h b/outcode.h new file mode 100644 index 00000000..a75be751 --- /dev/null +++ b/outcode.h @@ -0,0 +1,35 @@ +/* ------------------------------------------------------------------------ + The OutCode's for SICS have to be translated from text at several + places in SICS. Wherever necessary such code should include this file. + This restricts changes to Scommon.h and this file + + Mark Koennecke, November 1996 +----------------------------------------------------------------------------*/ +#ifndef POUTCODE +#define POUTCODE + +static char *pCode[] = { + "internal", + "command", + "hwerror", + "inerror", + "status", + "value", + "start", + "finish", + "event", + "warning", + "error", + "hdbvalue", + "hdbevent", + "log", + "logerror", + NULL +}; +static int iNoCodes = 15; + +const char* OutCodeToTxt(OutCode eOut); + +int OutCodeFromText(const char *text, OutCode *outcode); + +#endif diff --git a/perfmon.c b/perfmon.c index cc5c54c1..82abad67 100644 --- a/perfmon.c +++ b/perfmon.c @@ -41,7 +41,6 @@ #include #include "fortify.h" #include "sics.h" -#include "servlog.h" #include "perfmon.h" #include "perfmon.i" /*-------------------------------------------------------------------------*/ @@ -125,10 +124,6 @@ int IncrementPerfMon(pPerfMon self) self->iCount = 0; self->tLast = tCurrent; self->tTarget = tCurrent + self->iInteg; - if (self->iLog) { - snprintf(pBueffel,sizeof(pBueffel)-1, "PerfMon = %f", self->fCPS); - SICSLogWrite(pBueffel, eValue); - } InvokeCallBack(self->pCall, VALUECHANGE, &self->fCPS); traceSys("perfmon","%d:%f", self->iInteg, self->fCPS); } @@ -160,7 +155,7 @@ static int InterestCallback(int iEvent, void *pEvent, void *pUser) } snprintf(pBueffel,sizeof(pBueffel)-1, "Performance = %f", *fPos); - SCWrite(pCon, pBueffel, eValue); + SCWrite(pCon, pBueffel, eEvent); return 1; } diff --git a/protocol.c b/protocol.c index cf62e8e2..61188038 100644 --- a/protocol.c +++ b/protocol.c @@ -12,9 +12,8 @@ #include #include #include -#include +#include #include -#include "commandlog.h" #include "protocol.h" #include @@ -572,19 +571,12 @@ int SCWriteJSON_String(SConnection * pCon, char *pBuffer, int iOut) } else { iRet = 0; } - snprintf(pBueffel,sizeof(pBueffel)-1, "Next line intended for socket: %d", iRet); - SICSLogWrite(pBueffel, eInternal); - SICSLogWrite(pBuffer, iOut); /* write to commandlog if user or manager privilege */ - if (SCGetRights(pCon) <= usUser) { - if (pCon->iMacro != 1) { - WriteToCommandLogId(NULL, iRet, pBuffer); - } else { - if (iOut == eError || iOut == eWarning) { - WriteToCommandLogId(NULL, iRet, pBuffer); - } - } + if (SCGetRights(pCon) <= usUser && !SCinMacro(pCon)) { + Log(INFO,"com","sock%03.3d:%s",iRet, pBuffer); + } else { + Log(DEBUG,"com","sock%03.3d:%s", iRet, pBuffer); } if (SCinMacro(pCon)) { diff --git a/remob.c b/remob.c index 55a3ae01..35eb4d98 100644 --- a/remob.c +++ b/remob.c @@ -17,9 +17,7 @@ M. Zolliker July 04 #include "remob.h" #include "splitter.h" #include "status.h" -#include "servlog.h" #include "site.h" -#include "commandlog.h" /*-------------------------------------------------------------------------*/ #define INTERRUPTMODE 0 #define ACCESSCODE 1 @@ -275,7 +273,7 @@ static int RemServerTask(void *data) continue; if (strstr(rc->line, " ") == rc->line) { - WriteToCommandLog("REMOB>", "infinite echo loop detected"); + Log(ERROR,"sys","%s:%s","REMOB", "infinite echo loop detected"); continue; } if (isUser == 0) { @@ -629,7 +627,7 @@ static int InterestCallback(int iEvent, void *pEvent, void *pUser) snprintf(buf, sizeof(buf), "%s.position = %g ", pInfo->pName, psCall->fVal); - SCWrite(pInfo->pCon, buf, eValue); + SCWrite(pInfo->pCon, buf, eEvent); return 1; } diff --git a/remoteobject.c b/remoteobject.c index 0e78a3a4..ffcf0609 100644 --- a/remoteobject.c +++ b/remoteobject.c @@ -476,7 +476,7 @@ static int HeartbeatTask(void *pData) termination. -----------------------------------------------------------------------------------*/ -#include +#include static OutCode findOutCode(char *txt) { int i; diff --git a/scan.c b/scan.c index 4e989264..0493471d 100644 --- a/scan.c +++ b/scan.c @@ -1201,10 +1201,10 @@ static int ScanInterest(int iEvent, void *pEventData, void *pUser) } if (iEvent == SCANSTART) { - SCWrite(pCon, "NewScan", eLog); + SCWrite(pCon, "NewScan", eEvent); return 1; } else if (iEvent == SCANEND) { - SCWrite(pCon, "ScanEnd", eLog); + SCWrite(pCon, "ScanEnd", eEvent); return 1; } else if (iEvent == SCANPOINT) { /* allocate space */ @@ -1231,7 +1231,7 @@ static int ScanInterest(int iEvent, void *pEventData, void *pUser) strcat(pPtr, "}"); oldWrite = SCGetWriteFunc(pCon); SCSetWriteFunc(pCon, SCOnlySockWrite); - SCWrite(pCon, pPtr, eLog); + SCWrite(pCon, pPtr, eEvent); SCSetWriteFunc(pCon, oldWrite); free(lData); free(pPtr); @@ -1264,10 +1264,10 @@ static int ScanDynInterest(int iEvent, void *pEventData, void *pUser) } if (iEvent == SCANSTART) { - SCWrite(pCon, "NewScan", eLog); + SCWrite(pCon, "NewScan", eEvent); return 1; } else if (iEvent == SCANEND) { - SCWrite(pCon, "ScanEnd", eLog); + SCWrite(pCon, "ScanEnd", eEvent); return 1; } else if (iEvent == SCANPOINT) { i = self->iCounts - 1; @@ -1287,7 +1287,7 @@ static int ScanDynInterest(int iEvent, void *pEventData, void *pUser) } snprintf(pBueffel, 255, "%s.scanpoint = {%d %f %ld}", self->objectName, i, fVal, lVal); - SCWrite(pCon, pBueffel, eLog); + SCWrite(pCon, pBueffel, eEvent); } return 1; } @@ -1315,10 +1315,10 @@ static int ScanUUInterest(int iEvent, void *pEventData, void *pUser) } if (iEvent == SCANSTART) { - SCWrite(pCon, "NewScan", eLog); + SCWrite(pCon, "NewScan", eEvent); return 1; } else if (iEvent == SCANEND) { - SCWrite(pCon, "ScanEnd", eLog); + SCWrite(pCon, "ScanEnd", eEvent); return 1; } else if (iEvent == SCANPOINT) { /* allocate space */ diff --git a/scriptcontext.c b/scriptcontext.c index f6deac5b..7d68abc6 100644 --- a/scriptcontext.c +++ b/scriptcontext.c @@ -6,7 +6,6 @@ #include "sicsobj.h" #include "splitter.h" #include "initializer.h" -#include "commandlog.h" #include "hipadaba.h" #include "sicshipadaba.h" #include "dynstring.h" @@ -516,14 +515,14 @@ static char *SctActionHandler(void *actionData, char *lastReply, emsg = GetHdbProp(node, eprop); if (emsg == NULL || con != controller->conn) { GetHdbPath(node, path, sizeof path); - SCPrintf(con, eLogError, - "ERROR: action {%s} in {%s} node %s:\nERROR: %s", + snprintf(msg,sizeof(msg),"ERROR: action {%s} in {%s} node %s:\nERROR: %s", data->name, origScript, path, result); + SCPureSockWrite(con, msg,eLogError); if(data != NULL && data->controller != NULL){ - traceIO(data->controller->node->name, "ERROR: action {%s} in {%s} node %s:\nERROR: %s", + traceIO(data->controller->node->name, "ERROR: action {%s} in {%s} node %s:ERROR: %s", data->name, origScript, path, result); } else { - traceIO("sctunknown", "ERROR: action {%s} in {%s} node %s:\nERROR: %s", + traceIO("sctunknown", "ERROR: action {%s} in {%s} node %s:ERROR: %s", data->name, origScript, path, result); } } @@ -600,7 +599,7 @@ static char *SctActionHandler(void *actionData, char *lastReply, */ iMacro = SCinMacro(con); con->iMacro = 0; - SCWrite(con, "o.k.", eWarning); + SCPureSockWrite(con, "o.k.", eLog); SCsetMacro(con, iMacro); } } @@ -637,7 +636,8 @@ static char *SctActionHandler(void *actionData, char *lastReply, if (send == NULL) send = ""; if (controller->verbose) { - SCPrintf(con, eLog, "%6.3f send : %s", secondsOfMinute(), send); + snprintf(msg,sizeof(msg),"%6.3f send : %s", secondsOfMinute(), send); + SCPureSockWrite(con, msg,eLog); } if (controller->fd != NULL) { fprintf(controller->fd, "%6.3f send : %s\n", secondsOfMinute(), send); @@ -838,7 +838,6 @@ static hdbCallbackReturn SctActionCallback(Hdb * node, void *userData, if (script != NULL) { if (SctCallInContext(con, script, node, data->controller, &error) == 0) { - /* SCPrintf(con, eError, "ERROR: in {%s}: %s", script, error); */ SCPrintf(con, eError, "ERROR: %s", error); /* nicer for the user */ SetHdbProperty(node, "target", NULL); SetHdbProperty(node, "requested", NULL); diff --git a/servlog.c b/servlog.c deleted file mode 100644 index 90ab59a8..00000000 --- a/servlog.c +++ /dev/null @@ -1,610 +0,0 @@ -/*--------------------------------------------------------------------------- - - Implementation for the server log. - - Is a bit tricky. Writes 1000 lines to a file, than increments - and opens a new one. Wraps arounf after 3. This is a compromise - between error tracking and use of diskspace. - - - - Mark Koennecke, October 1996 - - Copyright: - - Labor fuer Neutronenstreuung - Paul Scherrer Institut - CH-5423 Villigen-PSI - - - The authors hereby grant permission to use, copy, modify, distribute, - and license this software and its documentation for any purpose, provided - that existing copyright notices are retained in all copies and that this - notice is included verbatim in any distributions. No written agreement, - license, or royalty fee is required for any of the authorized uses. - Modifications to this software may be copyrighted by their authors - and need not follow the licensing terms described here, provided that - the new terms are clearly indicated on the first page of each file where - they apply. - - IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY - FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES - ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY - DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - - THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE - IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE - NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR - MODIFICATIONS. - - Modified: Paul Hathaway, June 2004 - SICSLogWrite - - no longer asserts existence of the log file, writing - to stderr and skipping further file writes. - - NETWrites log message (if enabled) before attempt to write to file - - uses OpenVerifyLogFile helper function (removed duplicate code) ------------------------------------------------------------------------------*/ -#include -#include "fortify.h" -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ifile.h" -#include "servlog.h" -#include "network.h" - -/* define this, if you do not want a server log - -#define NOLOG 1 -*/ -/* ------------------------------------------------------------------------- - The server log output can be captured by a client. In order to implement - this the following code is necessary. -*/ -typedef struct __LogLog { - pSICSLogHook pFunc; - void *pData; - unsigned int code_bits; - struct __LogLog *pNext; - struct __LogLog *pPrevious; -} CaptureEntry, *pCaptureEntry; - -static pCaptureEntry pCapture = NULL; -/*------------------------------------------------------------------------*/ -#include "outcode.c" /* for pCode */ - -const char* OutCodeToTxt(OutCode eOut) -{ - switch (eOut) { - case eInternal: return "Int"; /* internal */ - case eCommand: return "Cmd"; /* reserved, not used */ - case eHWError: return "ErH"; /* reserved, used only for SICSLog */ - case eInError: return "ErI"; /* reserved, used as a mark in the handling of output codes */ - case eStatus: return "Sta"; /* reserved, deprecated */ - case eValue: return "Val"; /* value reponse: copied into Tcl */ - case eStart: return "Beg"; /* start message */ - case eFinish: return "End"; /* finish message */ - case eEvent: return "Evt"; /* some callback messages */ - case eWarning: return "Wrn"; /* warnings */ - case eError: return "Err"; /* error: copied into Tcl */ - case eHdbValue: return "HVa"; /* hipadaba value chnage */ - case eHdbEvent: return "HEv"; /* Hipadaba event */ - case eLog: return "Log"; /* log message: is always written to client */ - case eLogError: return "ErL"; /* error message to log: is always written to client */ - } - return "???"; -} - -const char* OutCodeToText(OutCode eOut) -{ - switch (eOut) { - case eInternal: return "Internal"; - case eCommand: return "Command"; - case eHWError: return "HWError"; - case eInError: return "InError"; - case eStatus: return "Status"; - case eValue: return "Value"; - case eStart: return "Start"; - case eFinish: return "Finish"; - case eEvent: return "Event"; - case eWarning: return "Warning"; - case eError: return "Error"; - case eHdbValue: return "HdbValue"; - case eHdbEvent: return "HdbEvent"; - case eLog: return "Log"; - case eLogError: return "LogError"; - } - return "Unknown"; -} - -int OutCodeFromText(const char *text, OutCode *outcode) -{ - int i; - for (i = 0; i < iNoCodes; ++i) { - if (strcasecmp(text, pCode[i]) == 0) { - if (outcode) - *outcode = i; - return i; - } - } - return -1; -} - -static unsigned int find_code_bits(const char *p1, const char *p2) { - /* may be outcode, try find it */ - int i; - const char *pShort; - const char *pLong; - size_t len = p2 - p1; - if (len == 3 && strncasecmp(p1, "all", 3) == 0) - return (1 << iNoCodes) - 1; - for (i = 0; i < iNoCodes; ++i) { - pShort = OutCodeToTxt(i); - if (pShort && strncasecmp(p1, pShort, len) == 0) - return 1 << i; - pLong = OutCodeToText(i); - if (pLong && strlen(pLong) == len) { - if (strncasecmp(p1, pLong, len) == 0) { - return 1 << i; - } - } - } - return 0; -} - -char *AddSICSLogHook(pSICSLogHook func, const char *pCodes, void *pData) -{ - unsigned int code_bits = 0; - if (strcasecmp("all", pCodes) == 0) - code_bits = (1 << iNoCodes) - 1; - else { - const char *p1, *p2; - p1 = pCodes; - while (NULL != (p2 = strchr(p1, ','))) { - /* TODO [p1:p2) */ - code_bits |= find_code_bits(p1, p2); - p1 = p2 + 1; - } - /* p1 points at the last or only code */ - /* TODO p1 */ - code_bits |= find_code_bits(p1, p1 + strlen(p1)); - } - if (code_bits != 0) { - pCaptureEntry pNew; - pNew = (pCaptureEntry) malloc(sizeof(CaptureEntry)); - if (!pNew) { - SICSLogWrite("Out of memory in LogCapture", eInternal); - return NULL; - } - if (pCapture) { - pCapture->pPrevious = pNew; - } - pNew->pPrevious = NULL; - pNew->pNext = pCapture; - pCapture = pNew; - pNew->code_bits = code_bits; - pNew->pFunc = func; - pNew->pData = pData; - } - return NULL; -} - -/* Remove any and all hooks with this pData */ -char *RemSICSLogHook(void *pData) -{ - pCaptureEntry pCurrent, pTemp; - - /* find first */ - pCurrent = pCapture; - while (pCurrent != NULL) { - if (pData == pCurrent->pData) { - /* relink */ - if (pCurrent->pPrevious) { - pCurrent->pPrevious->pNext = pCurrent->pNext; - } else { - pCapture = pCurrent->pNext; - } - if (pCurrent->pNext) { - pCurrent->pNext->pPrevious = pCurrent->pPrevious; - } - pTemp = pCurrent->pNext; - /* get rid of pCurrent */ - free(pCurrent); - pCurrent = pTemp; - } else { - pCurrent = pCurrent->pNext; - } - } - return NULL; -} - -/* Return bitmask of any and all hooks with this pData */ -unsigned int GetSICSLogHook(void *pData) -{ - pCaptureEntry pCurrent, pTemp; - unsigned int code_bits = 0; - - /* find first */ - pCurrent = pCapture; - while (pCurrent != NULL) { - if (pData == pCurrent->pData) { - code_bits |= pCurrent->code_bits; - } - pCurrent = pCurrent->pNext; - } - return code_bits; -} - - -/*--------------------------------------------------------------------------*/ -static int HasLineFeed(char *pText) -{ - int i; - - for (i = strlen(pText); i > 0; i--) { - if (pText[i] == '\n') { - return 1; - } - if (isalpha(pText[i])) { - return 0; - } - } - return 1; -} - -/*---------------------------------------------------------------------------*/ -static const char* timestamp(struct timeval *tp, char delim) { - static char ts[80]; - int year, month, day; - int hour, min, sec, usec; - struct timeval tv; - struct tm *time; - if (tp) - tv = *tp; - else - gettimeofday(&tv, NULL); - time = localtime(&tv.tv_sec); - year = 1900 + time->tm_year; - month = time->tm_mon + 1; - day = time->tm_mday; - hour = time->tm_hour; - min = time->tm_min; - sec = time->tm_sec; - usec = (int) tv.tv_usec; - snprintf(ts, 80, "%04d-%02d-%02dT%02d%c%02d%c%02d.%06d", - year, month, day, hour, delim, min, delim, sec, usec); - return ts; -} - -/*---------------------------------------------------------------------------*/ -#define MAXLOG 100000 -#define MAXFILES 100 - -static FILE *fLogFile = NULL; -static int iFile = 0; -static int iLineCount = 0; -static int iLogUsable = 1; -static char filnam[1024]; -static char prevfilnam[1024]; - -/*---------------------------------------------------------------------------*/ -int OpenVerifyLogFile() -{ - char pFile[256]; - char *pChar = NULL; - char fPath[1024]; - - pChar = getenv("SICS_INIT_LOGPATH"); - if (!pChar) { - snprintf(fPath, sizeof(fPath) - 1, "%s/", "../log"); - } else { - snprintf(fPath, sizeof(fPath) - 1, "%s/", pChar); - } - - pChar = IFindOption(pSICSOptions, "LogFileBaseName"); - if (!pChar) { /* Try to write to file "server" in */ - strcpy(pFile, "server"); - } else { - strlcpy(pFile, pChar, sizeof(pFile) - 1); - } - - snprintf(filnam, sizeof(filnam) - 1, "%s%s_%19.19s.%02d.log", fPath, pFile, timestamp(NULL, '-'), iFile); - iFile++; - if (iFile >= MAXFILES) { - iFile = 0; - } - - fLogFile = fopen(filnam, "w"); - if (!fLogFile) { - fprintf(stderr, "ERROR: Cannot open logfile %s for writing\n", pFile); - fLogFile = NULL; - return 0; - } else { - return 1; - } -} - -/*---------------------------------------------------------------------------*/ -void SICSLogEnable(int flag) -{ - iLogUsable = flag; -} - -/*---------------------------------------------------------------------------*/ -static void SICSLogWriteFile(char *pText, OutCode eOut, struct timeval *tp) -{ - pCaptureEntry pCurrent; - int text_len; - -#ifdef NOLOG - return; -#endif - - text_len = strlen(pText); - /* do all captured */ - pCurrent = pCapture; - while (pCurrent) { - if ((pCurrent->code_bits & (1 << eOut))) { - pCurrent->pFunc(pText, eOut, pCurrent->pData); - } - pCurrent = pCurrent->pNext; - } - - if (0 == iLogUsable) - return; - - if (fLogFile == NULL) { /* first time of use */ - /* no options: startup or serious trouble, print to stdout */ - if (!pSICSOptions) { - printf("WARNING: Cannot log(%s)\n", pText); - return; - } - iLogUsable = OpenVerifyLogFile(); - iLineCount = 0; - } - - /* switch file if too many lines */ - if (iLineCount >= MAXLOG) { - strcpy(prevfilnam, filnam); - FILE *prevlog = fLogFile; - - iLogUsable = OpenVerifyLogFile(); - iLineCount = 0; - fprintf(prevlog, "%s: <<>> to %s\n", - timestamp(NULL, ':'), - filnam); - fclose(prevlog); - if (1 == iLogUsable) { - fprintf(fLogFile, "%s: <<>> from %s\n", - timestamp(NULL, ':'), - prevfilnam); - iLineCount++; - } - } - - if (1 == iLogUsable) { - if (iLineCount == 0) - fprintf(fLogFile, "%s: <<>>\n", timestamp(NULL, ':')); - fprintf(fLogFile, "%s:%s:", timestamp(tp, ':'), OutCodeToTxt(eOut)); - fprintf(fLogFile, "%s", pText); - if (text_len < 1 || pText[text_len - 1] != '\n') - fprintf(fLogFile, "\n"); - fflush(fLogFile); - iLineCount++; - } -} - -void SICSLogWriteTimeCode(char *pText, OutCode eOut, struct timeval *tp, char code) -{ - char buf[200]; - const char *cp; - int idx = 0; - struct timeval tv; - - if (tp == NULL) { - gettimeofday(&tv, NULL); - tp = &tv; - } - if (isalnum(code)) { - buf[idx++] = code; - buf[idx++] = ':'; - } - cp = pText; - while (*cp) { - if (*cp == '\n') { - buf[idx++] = '\n'; - buf[idx++] = '\0'; - SICSLogWriteFile(buf, eOut, tp); - idx = 0; - buf[idx++] = '*'; - buf[idx++] = ':'; - } else if (*cp == '\r') { - buf[idx++] = '\\'; - buf[idx++] = 'r'; - } else if (*cp == '\t') { - buf[idx++] = '\\'; - buf[idx++] = 't'; - } else if (*cp < ' ' || *cp > '~') { - const char hex[] = "0123456789ABCDEF"; - buf[idx++] = '<'; - buf[idx++] = hex[(*cp >> 4) & 0xF]; - buf[idx++] = hex[(*cp) & 0xF]; - buf[idx++] = '>'; - } else { - buf[idx++] = *cp; - } - cp++; - if (idx > 132) { - buf[idx++] = '\n'; - buf[idx++] = '\0'; - SICSLogWriteFile(buf, eOut, tp); - idx = 0; - buf[idx++] = '*'; - buf[idx++] = ':'; - } - } - /* Suppress the spurious blank lines caused by trailing newlines */ - if (idx == 2 && buf[0] == '*' && buf[1] == ':') - return; - if (idx > 0) { - buf[idx++] = '\n'; - buf[idx++] = '\0'; - SICSLogWriteFile(buf, eOut, tp); - } -} - -void SICSLogWriteCode(char *pText, OutCode eOut, char code) -{ - SICSLogWriteTimeCode(pText, eOut, NULL, code); -} - -void SICSLogWriteTime(char *pText, OutCode eOut, struct timeval *tp) -{ - SICSLogWriteTimeCode(pText, eOut, tp, 'L'); -} - -void SICSLogWrite(char *pText, OutCode eOut) -{ - SICSLogWriteTime(pText, eOut, NULL); -} - -void SICSLogWriteHexTime(const char *text, int count, OutCode eOut, - struct timeval *tp) -{ - const char hex[] = "0123456789ABCDEF"; - char addr[20], left[80], right[80]; - char *lp = left; - char *rp = right; - int i; - int duplicates; - /* Limit the output */ - if (count > 1024) - count = 1024; - duplicates = 0; - for (i = 0; i < count; ++i) { - if ((i & 0xF) == 0) { - if (i > 0) { - char line[132]; - snprintf(line, sizeof(line) - 1, "%-6s: %-49s | %-17s |", addr, - left, right); - SICSLogWriteTime(line, eOut, tp); - } - snprintf(addr, sizeof(addr) - 1, "0x%04X", i); - while (i >= 16 && i + 16 < count) { - if (memcmp(&text[i - 16], &text[i], 16) != 0) - break; - ++duplicates; - i += 16; - } - if (duplicates > 0) { - if (duplicates > 1) { - char line[132]; - snprintf(line, sizeof(line) - 1, "%-6s: ... (%d duplicates)", - addr, duplicates); - SICSLogWriteTime(line, eOut, tp); - } else { - char line[132]; - snprintf(line, sizeof(line) - 1, "%-6s: %-49s | %-17s |", addr, - left, right); - SICSLogWriteTime(line, eOut, tp); - } - duplicates = 0; - } - snprintf(addr, sizeof(addr) - 1, "0x%04X", i); - lp = left; - rp = right; - } - *lp++ = hex[(text[i] >> 4) & 0xF]; - *lp++ = hex[(text[i]) & 0xF]; - *lp++ = ' '; - if (text[i] >= ' ' && text[i] <= '~') - *rp++ = text[i]; - else - *rp++ = '.'; - /* if we just did slot 7, insert an extra space */ - if ((i & 0xF) == 7) { - *lp++ = ' '; - *rp++ = ' '; - } - *lp = *rp = '\0'; - } - if (i > 0) { - char line[132]; - snprintf(line, sizeof(line) - 1, "%-6s: %-49s | %-17s |", addr, left, - right); - SICSLogWriteTime(line, eOut, tp); - } -} - -void SICSLogWriteHex(const char *text, int count, OutCode eOut) -{ - SICSLogWriteHexTime(text, count, eOut, NULL); -} - -void SICSLogTimePrintf(OutCode eOut, struct timeval *tp, const char *fmt, - ...) -{ - va_list ap; - char buf[256]; - char *dyn; - unsigned int l; - int res; - - va_start(ap, fmt); - l = vsnprintf(buf, sizeof buf, fmt, ap); - va_end(ap); - if (l >= sizeof buf) { - /* we have probably a C99 conforming snprintf and - need a larger buffer - */ - dyn = malloc(l + 1); - if (dyn != NULL) { - va_start(ap, fmt); - vsnprintf(dyn, l + 1, fmt, ap); - va_end(ap); - SICSLogWriteTime(dyn, eOut, tp); - free(dyn); - return; - } - } - SICSLogWriteTime(buf, eOut, tp); - return; -} - -void SICSLogPrintf(OutCode eOut, const char *fmt, ...) -{ - va_list ap; - char buf[256]; - char *dyn; - unsigned int l; - int res; - - va_start(ap, fmt); - l = vsnprintf(buf, sizeof buf, fmt, ap); - va_end(ap); - if (l >= sizeof buf) { - /* we have probably a C99 conforming snprintf and - need a larger buffer - */ - dyn = malloc(l + 1); - if (dyn != NULL) { - va_start(ap, fmt); - vsnprintf(dyn, l + 1, fmt, ap); - va_end(ap); - SICSLogWrite(dyn, eOut); - free(dyn); - return; - } - } - SICSLogWrite(buf, eOut); - return; -} diff --git a/servlog.h b/servlog.h deleted file mode 100644 index 99fafc0a..00000000 --- a/servlog.h +++ /dev/null @@ -1,40 +0,0 @@ -/*-------------------------------------------------------------------------- - - The server LOG. Logs all connection requests, internal server - errors, SW-errors, HW-problems, commands etc. - - Additionally implements a capture command which allows to get - log output for a client. - - Mark Koennecke, October 1996, November 1996 - - - copyright: see implementation file ---------------------------------------------------------------------------*/ - -#ifndef SICSLOG -#define SICSLOG -#include "Scommon.h" -void SICSLogWrite(char *ptext, OutCode eOut); -void SICSLogWriteTime(char *ptext, OutCode eOut, struct timeval *tp); -void SICSLogWriteCode(char *ptext, OutCode eOut, char code); -void SICSLogWriteTimeCode(char *ptext, OutCode eOut, struct timeval *tp, char code); -void SICSLogWriteHex(const char *text, int count, OutCode eOut); -void SICSLogWriteHexTime(const char *text, int count, OutCode eOut, - struct timeval *tp); -#if __GNUC__ > 2 -#define G_GNUC_PRINTF( format_idx, arg_idx ) \ - __attribute__((__format__ (__printf__, format_idx, arg_idx))) -#else -#define G_GNUC_PRINTF( format_idx, arg_idx ) -#endif -void SICSLogPrintf(OutCode eOut, const char *fmt, ...) G_GNUC_PRINTF (2, 3); -void SICSLogTimePrintf(OutCode eOut, struct timeval *tp, const char *fmt, - ...) G_GNUC_PRINTF (3, 4); -#undef G_GNUC_PRINTF -void SICSLogEnable(int flag); -typedef void (*pSICSLogHook)(const char *pText, OutCode eOut, void *pData); -char *AddSICSLogHook(pSICSLogHook func, const char *pCodes, void *pData); -char *RemSICSLogHook(void *pData); -unsigned int GetSICSLogHook(void *pData); -#endif diff --git a/sics.h b/sics.h index 9dce3623..f3108bee 100644 --- a/sics.h +++ b/sics.h @@ -36,8 +36,8 @@ typedef enum { #include "devexec.h" #include "emon.h" #include "nserver.h" -#include "servlog.h" #include "sicsutil.h" +#include "logv2.h" #include "trace.h" extern pServer pServ; diff --git a/sicscron.c b/sicscron.c index 0ad5ae63..d6740881 100644 --- a/sicscron.c +++ b/sicscron.c @@ -20,7 +20,6 @@ #include "sics.h" #include "splitter.h" #include "sicscron.h" -#include "commandlog.h" typedef struct { int iInterval; diff --git a/sicsget.c b/sicsget.c index f4feb803..a97fad46 100644 --- a/sicsget.c +++ b/sicsget.c @@ -334,7 +334,7 @@ static int GetHdbFunc(void *ms, void *userData) char *geterror = NULL, error[512]; hdbValue ve; - node = FindHdbNode(NULL,self->name,NULL); + node = FindHdbNode(NULL,self->name,pServ->dummyCon); if(node != NULL){ geterror = GetHdbProp(node,"geterror"); if(geterror != NULL){ diff --git a/sicshipadaba.c b/sicshipadaba.c index b10a9a92..ae8d4e3e 100644 --- a/sicshipadaba.c +++ b/sicshipadaba.c @@ -38,7 +38,6 @@ #include #include "sicsobj.h" #include -#include "commandlog.h" #include "arrayutil.h" #include "HistMem.h" #include "asynnet.h" @@ -904,9 +903,7 @@ static hdbCallbackReturn SICSScriptReadCallback(pHdb node, void *userData, if (pCon != NULL) { MacroPush(pCon); } - SetWriteHistory(0); status = Tcl_Eval(InterpGetTcl(pServ->pSics), command); - SetWriteHistory(1); if (pCon != NULL) { MacroPop(); } diff --git a/sicvar.c b/sicvar.c index dbf496d8..56ca48e9 100644 --- a/sicvar.c +++ b/sicvar.c @@ -363,19 +363,19 @@ static int VarInterestCallback(int iEvent, void *pEvent, void *pUser) case veInt: VarGetInt(pVar, &iVal); snprintf(pBueffel,sizeof(pBueffel)-1, "%s = %d", pVar->name, iVal); - SCWrite(pCon, pBueffel, eValue); + SCWrite(pCon, pBueffel, eEvent); status = 1; break; case veFloat: VarGetFloat(pVar, &fVal); snprintf(pBueffel,sizeof(pBueffel)-1, "%s = %f", pVar->name, fVal); - SCWrite(pCon, pBueffel, eValue); + SCWrite(pCon, pBueffel, eEvent); status = 1; break; case veText: VarGetText(pVar, &pText); snprintf(pBueffel,sizeof(pBueffel)-1, "%s = %s", pVar->name, pText); - SCWrite(pCon, pBueffel, eValue); + SCWrite(pCon, pBueffel, eEvent); if (pText) { free(pText); } diff --git a/simdriv.c b/simdriv.c index 0f123a6a..66b088c3 100644 --- a/simdriv.c +++ b/simdriv.c @@ -50,8 +50,8 @@ #include "fortify.h" #include "conman.h" #include "modriv.h" -#include "servlog.h" #include "splitter.h" +#include "logv2.h" /*-------------------------------------------------------------------------*/ static float SimRandom(void) { @@ -175,7 +175,7 @@ static int SimFix(void *self, int iError, float fNew) return MOTREDO; } - SICSLogWrite("Simulated Motor dying randomly", eHWError); + Log(ERROR,"dev","%s","Simulated Motor dying randomly"); if (fRand < 0.3333) { return MOTOK; } else if (fRand < 0.66666) { diff --git a/simev.c b/simev.c index 84349012..03535470 100644 --- a/simev.c +++ b/simev.c @@ -43,10 +43,9 @@ #include #include #include - +#include "logv2.h" #include "fortify.h" #include "conman.h" -#include "servlog.h" #include "fortify.h" #include "evdriver.h" @@ -200,7 +199,7 @@ static int SimFix(pEVDriver self, int iError) return DEVREDO; } - SICSLogWrite("Simulated Environment device dying randomly", eHWError); + Log(ERROR,"dev","%s","Simulated Environment device dying randomly"); if (fRand < 0.3333) { return DEVOK; } else if (fRand < 0.66666) { diff --git a/sinfox.c b/sinfox.c index 8b7874ad..833e2d83 100644 --- a/sinfox.c +++ b/sinfox.c @@ -14,7 +14,7 @@ #include /* incl. SCWrite */ #include #include -#include +#include #include #include "sinfox.h" diff --git a/stack_trace.c b/stack_trace.c index 911994ca..56f8dce5 100644 --- a/stack_trace.c +++ b/stack_trace.c @@ -201,18 +201,18 @@ size_t get_size_of_files(char *glob) { while (read(pipefd[0], &buff, 1) > 0) { DynStringConcatChar(s, buff); if (buff == '\n') { - SICSLogWrite(GetCharArray(s), eLog); + Log(DEBUG,"sys","%s",GetCharArray(s)); int this_size = atoi(GetCharArray(s)); total_size += this_size; DynStringClear(s); } } if (GetDynStringLength(s) > 0) - SICSLogWrite(GetCharArray(s), eLogError); + Log(DEBUG,"sys","%s",GetCharArray(s)); DeleteDynString(s); close(pipefd[0]); waitpid(child_pid, NULL, 0); - SICSLogPrintf(eLog, "Total size of files \"%s\" is %ldK", glob, (long int)total_size); + Log(DEBUG,"sys", "Total size of files \"%s\" is %ldK", glob, (long int)total_size); return total_size; } } @@ -260,7 +260,7 @@ void generate_stack_trace(int full, int dump) { while (read(pipefd[0], &buff, 1) > 0) { DynStringConcatChar(s, buff); } - SICSLogWrite(GetCharArray(s), eLogError); + Log(DEBUG,"sys","%s",GetCharArray(s)); DeleteDynString(s); close(pipefd[0]); waitpid(child_pid, NULL, 0); diff --git a/statemon.c b/statemon.c index 56b0ca8e..06171088 100644 --- a/statemon.c +++ b/statemon.c @@ -113,11 +113,11 @@ static int StateInterest(int iEvent, void *pEvent, void *pUser) } if (iEvent == STSTART) { snprintf(buffer, 255, "STARTED = %s", device); - SCWrite(pCon, buffer, eWarning); + SCWrite(pCon, buffer, eEvent); } if (iEvent == STEND) { snprintf(buffer, 255, "FINISH = %s", device); - SCWrite(pCon, buffer, eWarning); + SCWrite(pCon, buffer, eEvent); } return 1; } @@ -205,11 +205,11 @@ static int StateHdbInterest(int iEvent, void *pEvent, void *pUser) path = GetHipadabaPath(node); if (iEvent == STSTART) { snprintf(buffer, 1024, "%s STARTED", path); - SCWrite(pCon, buffer, eWarning); + SCWrite(pCon, buffer, eEvent); } if (iEvent == STEND) { snprintf(buffer, 1024, "%s FINISH", path); - SCWrite(pCon, buffer, eWarning); + SCWrite(pCon, buffer, eEvent); } if (path != NULL) { free(path); diff --git a/status.c b/status.c index db5c61a9..32556b6e 100644 --- a/status.c +++ b/status.c @@ -216,7 +216,7 @@ static int StatusCallback(int iEvent, void *pEvent, void *pUser) } snprintf(pBueffel,sizeof(pBueffel)-1, "status = %s", pText[(int) eCode]); - SCWrite(pCon, pBueffel, eLog); + SCWrite(pCon, pBueffel, eEvent); return 1; } diff --git a/taskobj.c b/taskobj.c index 371e177d..fa69befe 100644 --- a/taskobj.c +++ b/taskobj.c @@ -19,31 +19,31 @@ typedef struct { /*-------------------------------------------------------------------------*/ void TaskObjLogFunc(eTaskLogLevel lvl, const char *buf) { - OutCode eOut; + unsigned int severity; switch (lvl) { case eTaskLogNone: return; case eTaskLogInfo: - eOut = eValue; + severity = INFO; break; case eTaskLogDebug: - eOut = eValue; + severity = DEBUG; break; case eTaskLogWarning: - eOut = eWarning; + severity = WARN; break; case eTaskLogError: - eOut = eError; + severity = ERROR; break; case eTaskLogFatal: - eOut = eError; + severity = FATAL; break; default: - eOut = eValue; + severity = DEBUG; break; } - SICSLogWrite((char *)buf, eOut); + Log(severity, "task","%s",(char *)buf); return; } /*-------------------------------------------------------------------------*/ diff --git a/telnet.c b/telnet.c index fe23e39d..41d3171a 100644 --- a/telnet.c +++ b/telnet.c @@ -12,7 +12,6 @@ #include "sics.h" #include "passwd.h" #include "telnet.h" -#include "commandlog.h" #include "fortify.h" #define LOGINWAIT 300 /* 300 == 5 minutes to wait for valid username password */ @@ -165,7 +164,7 @@ int TelnetTaskOld(void *pData) iRet = IsValidUser(pUser, pPasswd); if (iRet < 0) { snprintf(pBuffer,sizeof(pBuffer)-1, "SYSTEM ATTACK by %s / %s", pUser, pPasswd); - SICSLogWrite(pBuffer, eInternal); + Log(FATAL,"sys","%s",pBuffer); SCWrite(self->pCon, "I do not know you, I do not let you in", eError); SendGA(self->pCon); @@ -175,8 +174,7 @@ int TelnetTaskOld(void *pData) NETInfo(self->pCon->pSock, pHost, 131); snprintf(pBuffer,sizeof(pBuffer)-1, "Accepted connection on socket %d from %s", self->pCon->pSock->sockid, pHost); - SICSLogWrite(pBuffer, eInternal); - WriteToCommandLog("SYS >", pBuffer); + Log(INFO,"com",pBuffer); SendWelcome(self->pCon); SCSetRights(self->pCon, iRet); self->iLogin = 1; @@ -273,7 +271,7 @@ int TelnetTask(void *pData) iRet = IsValidUser(pUser, pPasswd); if (iRet < 0) { snprintf(pBuffer,sizeof(pBuffer)-1, "SYSTEM ATTACK by %s / %s", pUser, pPasswd); - SICSLogWrite(pBuffer, eInternal); + Log(FATAL,"sys","%s",pBuffer); SCWrite(self->pCon, "I do not know you, I do not let you in", eError); SendGA(self->pCon); @@ -282,8 +280,7 @@ int TelnetTask(void *pData) } else { snprintf(pBuffer,sizeof(pBuffer)-1, "Accepted telnet connection on handle %d", self->pCon->sockHandle); - SICSLogWrite(pBuffer, eInternal); - WriteToCommandLog("SYS >", pBuffer); + Log(INFO,"com","%s",pBuffer); SendWelcome(self->pCon); SCSetRights(self->pCon, iRet); self->iLogin = 1; diff --git a/trace.c b/trace.c index a9ae51ee..f9e8af9f 100644 --- a/trace.c +++ b/trace.c @@ -21,6 +21,10 @@ * Enhanced to write time stamps any ten minutes. * * Mark Koennecke, October 2013 + * + * Modified to write to the new joined log + * + * Mark Koennecke, February 2016 */ #include @@ -203,20 +207,34 @@ static int strrepc(char *pszStr, char cFrom, char cTo) /*-----------------------------------------------------------------*/ void traceprint(char *sub, char *id, char *data) { - char *mysub, *myid, *mydata; + /* char *mysub, *myid, *mydata; */ - if(logFD != NULL && filter(sub,id)){ - mysub = strdup(sub); - myid = strdup(id); - mydata = strdup(data); - strrepc(mydata,'\n',':'); - strrepc(mysub,':','@'); - strrepc(myid,':','@'); - fprintf(logFD,"%s:%s:%lf:%s\n",mysub,myid,DoubleTime(),mydata); - free(mysub); - free(myid); - free(mydata); + /* if(logFD != NULL && filter(sub,id)){ */ + /* mysub = strdup(sub); */ + /* myid = strdup(id); */ + /* mydata = strdup(data); */ + /* strrepc(mydata,'\n',':'); */ + /* strrepc(mysub,':','@'); */ + /* strrepc(myid,':','@'); */ + /* fprintf(logFD,"%s:%s:%lf:%s\n",mysub,myid,DoubleTime(),mydata); */ + /* free(mysub); */ + /* free(myid); */ + /* free(mydata); */ + /* } */ + unsigned int severity; + + if(strstr(data,"ERROR") != NULL){ + severity = ERROR; + } else if(strstr(data,"WARNING") != NULL){ + severity = WARN; + } else if(strstr(sub,"com") != NULL){ + severity = INFO; + } else if(strstr(sub,"par") != NULL){ + severity = INFO; + } else { + severity = DEBUG; } + Log(severity,sub,"%s:%s",id,data); } /*-----------------------------------------------------------------*/ void traceIO(char *id, char *format, ...) @@ -558,13 +576,13 @@ void MakeTrace(void) return; } - cmd = AddSICSHdbPar(ccmd->objectNode, - "log", usMugger, MakeSICSFunc(TraceLog)); - AddSICSHdbPar(cmd, "filename", usMugger, MakeHdbText("")); + /* cmd = AddSICSHdbPar(ccmd->objectNode, */ + /* "log", usMugger, MakeSICSFunc(TraceLog)); */ + /* AddSICSHdbPar(cmd, "filename", usMugger, MakeHdbText("")); */ - cmd = AddSICSHdbPar(ccmd->objectNode, - "append", usMugger, MakeSICSFunc(TraceAppend)); - AddSICSHdbPar(cmd, "filename", usMugger, MakeHdbText("")); + /* cmd = AddSICSHdbPar(ccmd->objectNode, */ + /* "append", usMugger, MakeSICSFunc(TraceAppend)); */ + /* AddSICSHdbPar(cmd, "filename", usMugger, MakeHdbText("")); */ cmd = AddSICSHdbPar(ccmd->objectNode, @@ -577,4 +595,9 @@ void MakeTrace(void) AddCommand(pServ->pSics, "trace", InterInvokeSICSOBJ, KillTrace, ccmd); + /* + This is a really ugly hack to make tracing happen while we are switching + to the logging system + */ + logFD = (FILE*) 27; } diff --git a/uselect.c b/uselect.c index 8f8f9cfb..73246825 100644 --- a/uselect.c +++ b/uselect.c @@ -5,7 +5,6 @@ /* for logging */ #include "sics.h" -#include "commandlog.h" /* an uninterruptable version of select. M.Z. Oct 2008 */ @@ -29,7 +28,7 @@ int uselect(int nfds, } result = pselect(nfds, readfds, writefds, exceptfds, tmoPtr, &sigmask); if (result < 0 && errno == EINTR) { - WriteToCommandLog("SYS>", "pselect was interrupted!"); + Log(WARN,"sys", "%s", "pselect was interrupted!"); } return result; } diff --git a/varlog.c b/varlog.c index 910acaa2..633ebe34 100644 --- a/varlog.c +++ b/varlog.c @@ -56,7 +56,6 @@ #include "lld.h" #include "sics.h" #include "varlog.h" -#include "commandlog.h" #include "circular.h" #include "sicsdata.h" diff --git a/velo.c b/velo.c index 500d60e2..0f509f22 100644 --- a/velo.c +++ b/velo.c @@ -903,10 +903,10 @@ static int RotationInterest(int iEvent, void *pData, void *pUser) if (iEvent == ROTSTART) { snprintf(pBueffel,sizeof(pBueffel)-1, "%s Starting", pDat->pName); - SCWrite(pDat->pCon, pBueffel, eWarning); + SCWrite(pDat->pCon, pBueffel, eEvent); } else if (iEvent == ROTMOVE) { snprintf(pBueffel,sizeof(pBueffel)-1, "%s.rpm = %f", pDat->pName, *fVal); - SCWrite(pDat->pCon, pBueffel, eWarning); + SCWrite(pDat->pCon, pBueffel, eEvent); } return 1; } diff --git a/velosim.c b/velosim.c index 32eb85bc..cef52133 100644 --- a/velosim.c +++ b/velosim.c @@ -45,9 +45,9 @@ #include #include "fortify.h" #include "conman.h" -#include "servlog.h" #include "stringdict.h" #include "event.h" +#include "logv2.h" typedef struct __VelSelDriv *pVelSelDriv; #include "velodriv.h" @@ -190,7 +190,7 @@ static int SimFix(pVelSelDriv self, int iError) return VELOREDO; } - SICSLogWrite("Selector dying randomly", eHWError); + Log(ERROR,"dev","%s","Selector dying randomly"); if (fRand < 0.3333) { return VELOOK; } else if (fRand < 0.66666) {