- Added Sycamore protocol and command context to SICS
- Added sinfo to SICS - Added driver for TCP/IP Astrium velocity selector - Added driver for TCP/IP Astrium chopper controller SKIPPED: psi/amor2t.c psi/amorstat.c psi/dornier2.c psi/ecb.c psi/el734hp.c psi/fowrite.c psi/libpsi.a psi/make_gen psi/nextrics.c psi/pardef.c psi/pimotor.c psi/pipiezo.c psi/polterwrite.c psi/psi.c psi/scontroller.c psi/serial.c psi/tasinit.c psi/tasscan.c psi/tcpdocho.c psi/tcpdornier.c psi/tricssupport.c psi/velodornier.c
This commit is contained in:
110
servlog.c
110
servlog.c
@@ -39,6 +39,13 @@
|
||||
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 "fortify.h"
|
||||
#include <stdio.h>
|
||||
@@ -223,7 +230,38 @@
|
||||
static FILE *fLogFile = NULL;
|
||||
static int iFile = 0;
|
||||
static int iLineCount = 0;
|
||||
static int iLogUsable = 1;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int OpenVerifyLogFile()
|
||||
{
|
||||
char pFile[256];
|
||||
char *pChar = NULL;
|
||||
|
||||
pChar = IFindOption(pSICSOptions,"LogFileBaseName");
|
||||
if(!pChar)
|
||||
{ /* Try to write to file "server" in*/
|
||||
strcpy(pFile,"server");
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(pFile,pChar);
|
||||
}
|
||||
sprintf(pFile,"%s%2.2d.log",pFile, iFile);
|
||||
fLogFile = fopen(pFile,"w");
|
||||
if(!fLogFile)
|
||||
{
|
||||
fprintf(stderr,"ERROR: Cannot open logfile %s for writing\n",pFile);
|
||||
fLogFile = NULL;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void SICSLogWrite(char *pText, OutCode eOut)
|
||||
{
|
||||
char pFile[256];
|
||||
@@ -234,67 +272,47 @@
|
||||
#ifdef NOLOG
|
||||
return ;
|
||||
#endif
|
||||
if(fLogFile == NULL) /* first time of */
|
||||
|
||||
/* do all captured */
|
||||
pCurrent = pCapture;
|
||||
while(pCurrent)
|
||||
{
|
||||
if( (pCurrent->iOut == eOut) || (pCurrent->iAllFlag == 1) )
|
||||
{
|
||||
NETWrite(pCurrent->pCon->pSock,pText,strlen(pText));
|
||||
}
|
||||
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(" %s \n",pText);
|
||||
printf("WARNING: Cannot log(%s)\n",pText);
|
||||
return;
|
||||
}
|
||||
|
||||
/* get the filename */
|
||||
pChar = IFindOption(pSICSOptions,"LogFileBaseName");
|
||||
if(!pChar)
|
||||
{
|
||||
strcpy(pFile,"server");
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(pFile,pChar);
|
||||
}
|
||||
sprintf(pFile,"%s%2.2d.log",pFile, iFile);
|
||||
fLogFile = fopen(pFile,"w");
|
||||
if(!fLogFile)
|
||||
{
|
||||
printf("ERROR: cannot open logfile %s for writing\n",
|
||||
pFile);
|
||||
fLogFile = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
iLogUsable = OpenVerifyLogFile();
|
||||
}
|
||||
|
||||
/* switch file if to many lines */
|
||||
if(iLineCount == MAXLOG)
|
||||
/* switch file if too many lines */
|
||||
if(iLineCount >= MAXLOG)
|
||||
{
|
||||
fclose(fLogFile);
|
||||
fLogFile = NULL;
|
||||
iFile++;
|
||||
iLineCount = 0;
|
||||
if(iFile >= MAXFILES)
|
||||
{
|
||||
iFile = 0;
|
||||
}
|
||||
pChar = IFindOption(pSICSOptions,"LogFileBaseName");
|
||||
if(!pChar)
|
||||
{
|
||||
strcpy(pFile,"server");
|
||||
iLogUsable = OpenVerifyLogFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(pFile,pChar);
|
||||
}
|
||||
sprintf(pFile,"%s%1d.log",pFile, iFile);
|
||||
fLogFile = fopen(pFile,"w");
|
||||
if(!fLogFile)
|
||||
{
|
||||
printf("ERROR: cannot open logfile %s for writing\n",
|
||||
pFile);
|
||||
fLogFile = NULL;
|
||||
return;
|
||||
}
|
||||
iLineCount = 0;
|
||||
}
|
||||
|
||||
|
||||
if(1 == iLogUsable)
|
||||
{
|
||||
fprintf(fLogFile,"%s\n",pText);
|
||||
fflush(fLogFile);
|
||||
iLineCount++;
|
||||
@@ -309,5 +327,5 @@
|
||||
}
|
||||
pCurrent = pCurrent->pNext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user