Reduce log noise by setting iout = eInternal for macros. servlog.c Fixed timestamp in logfiles to get hours. hmm_configuration_common_1.tcl Added ML's mods to wombat config: ie BAT and FAT TABLE attributes and elements for multi-period acquisition and histo-streaming. Fixed "failed lsearch" bug. It's more robust to test for a non-successful lsearch instead of a failed lsearch. nxscripts_common_1.tcl SICS-297 Fixed Saving data series in a scratch file overwrites earlier entries. instdict_specification.tcl Added "scobj" kind and "sct_indexed_motor" sics object type for script context controllers and and objects. hipadaba_configuration_common.tcl Added sct_indexed_motor sics obj type to ::hdb::sobjadd and scobj kind to ::hdb::add_node sct_positmotor_common.tcl Update the index SICS variable when updating the current index value to make sure that the position is saved in the data file. You must now provide the hdb node_name when creating the sct posit motor. mk_sct_positmotor now sets the "param" and "long_name" attributes on the posit motor object util/utility.tcl Added ::utility::set_sct_indexed_motor_attributes to set SICS object attributes required for generating hdb info for an SCT_POSIT_MOTOR nxscript.c Merge the ansto mod to putslab (rev1.7) which adds support for saving unbuffered data from the histmem. sicshipadaba.c This incorporates the patch made to CommandSetCallback in rev1.10 so it can just be copied as is (ie no merge required). WARNING: There are changes to ListHdbNode to handle record separators which may affect us. Disabled sending hdb command start and stop messages because they break gumtree sicshdbfactory.c Disabled sending hdb command start and stop messages because they break gumtree hipadaba_configuration_common.tcl R2.4DEV The sct_posit_motor case of ::hdb::sobjadd is only needed to call add_node with kind=scobj. nxscripts_common_1.tcl R2.4DEV Added ::nexus::scobj::sdsinfo _gen_nxdict now skips nodes with data_type == "none" new util/script_context_util.tcl R2.4DEV Adds ::scobj::hinitprops command to initialise the hdb properties for script context object nodes. sct_positmotor_common.tcl R2.4DEV Use ::scobj::hinitprops utility command to initialise hdb properties on script context object parameter nodes. dynstring.c DynStringReplace should memcopy '\0', otherwise it can get the wrong length for iTextLen. Added DynStringReplaceWithLen to allow initialising a dynstring with char arrays which contain null chars and other non-ascii chars. Useful for read and write buffers in script context. ascon.c AsconRead return NULL for noResponse and AsconFailed otherwise the "result" node gets set with a spurious empty value. scriptcontext.c SctActionHandler only set the "result" node if there really is a reply. sicsobj.c Update from M.K. site_ansto.c Added galil and ordela hvps protocol handlers for scriptcontext. motor_dmc2280.c Allow home parameter to be outside of limits (for KOWARI) hardsup/makefile Added ordela HVPS protocol handler hardsup/sct_orhvpsprot.c New ordela HVPS protocol handler. Retries on NAKs and re-orders pot channels (ie toggles lower two bits). hardsup/sct_velselprot.c Start velocity selector protocol handler. hardsup/sct_galilprot.c Completed galil protocol handler. hipadaba_configuration_common.tcl Add new style SICS objects to hdb tree. instdict_specification.tcl Added scobj to kind list and sct_motor to sics object list. (and some housekeeping) hmm_configuration_common_1.tcl Added ratemaps to simulation. Fixe BAT_TABLE and added PERIOD_INDICES as per Mark Lesha's mods for multi-period acquisition. ratemaps now return float. sct_postimotor_common.tcl Now setting properties on the posit motor object so that it can be automatically added to the hdb tree. hrpd/config/motors/motor_configuration.tcl Fixed simulated msd motor so that it's handle properly in the hdb layer. sans/config/hmm/detector_ordela.tcl Updated the ordela calibration script to use the new sct_orhvpsprop.c script context controller. quokka_configuration.tcl Deleted lines which set the hdb properties for script context posit motors. This is now handled automatically as for other SICS objects. utility.tcl setpos now replaces the motor setpos subcommand. Added functions to set script context object attributes and sct_posit motor attributes. Created hparPath and hsibPath convenience commands for new-style SICS objects. script_context_util.tcl NEW! Adds hinitprops function to initialise the hdb properties for a script context object r2758 | ffr | 2008-12-12 17:53:53 +1100 (Fri, 12 Dec 2008) | 113 lines
373 lines
10 KiB
C
373 lines
10 KiB
C
/*---------------------------------------------------------------------------
|
|
|
|
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 "fortify.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <assert.h>
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
#include <time.h>
|
|
#include <sys/time.h>
|
|
#include "ifile.h"
|
|
#include "conman.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{
|
|
SConnection *pCon;
|
|
OutCode iOut;
|
|
int iAllFlag;
|
|
struct __LogLog *pNext;
|
|
struct __LogLog *pPrevious;
|
|
} CaptureEntry, *pCaptureEntry;
|
|
|
|
static pCaptureEntry pCapture = NULL;
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
int KillCapture(SConnection *pCon)
|
|
{
|
|
pCaptureEntry pCurrent, pTemp;
|
|
|
|
/* find first */
|
|
pCurrent = pCapture;
|
|
while(pCurrent != NULL)
|
|
{
|
|
if(pCon == pCurrent->pCon)
|
|
{
|
|
/* 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 1;
|
|
}
|
|
|
|
|
|
/* ------------------------------------------------------------------------
|
|
the command function:
|
|
Syntax:
|
|
Kill kills all logging
|
|
Log OutCode starts loggin OutCode events
|
|
All starts logging all events
|
|
-------------------------------------------------------------------------- */
|
|
#include "outcode.c" /* for pCode */
|
|
|
|
int LogCapture(SConnection *pCon, SicsInterp *pSics, void *pData,
|
|
int argc, char *argv[])
|
|
{
|
|
pCaptureEntry pNew = NULL;
|
|
char pBueffel[512];
|
|
int i;
|
|
|
|
/* check no af args */
|
|
if(argc < 2)
|
|
{
|
|
sprintf(pBueffel,"Insufficient number of argumenst to %s",argv[0]);
|
|
SCWrite(pCon,pBueffel,eError);
|
|
return 0;
|
|
}
|
|
argtolower(argc,argv);
|
|
|
|
/* Branch according to argv[1] */
|
|
if(strcmp(argv[1],"kill") == 0 )
|
|
{
|
|
KillCapture(pCon);
|
|
return 1;
|
|
}
|
|
else if(strcmp(argv[1],"all") == 0)
|
|
{
|
|
pNew = (pCaptureEntry)malloc(sizeof(CaptureEntry));
|
|
if(!pNew)
|
|
{
|
|
SICSLogWrite("Out of memory in LogCapture",eInternal);
|
|
return 0;
|
|
}
|
|
if(pCapture)
|
|
{
|
|
pCapture->pPrevious = pNew;
|
|
}
|
|
pNew->pPrevious = NULL;
|
|
pNew->pNext = pCapture;
|
|
pCapture = pNew;
|
|
pNew->iAllFlag = 1;
|
|
pNew->pCon = pCon;
|
|
return 1;
|
|
}
|
|
else
|
|
{
|
|
/* must be outcode, try find it */
|
|
i = 0;
|
|
while(pCode[i] != NULL)
|
|
{
|
|
if(strcmp(argv[1],pCode[i]) == 0)
|
|
{
|
|
break;
|
|
}
|
|
i++;
|
|
}
|
|
if(i > iNoCodes)
|
|
{
|
|
sprintf(pBueffel,"OutPutCode %s not recognized in %s",argv[1],
|
|
argv[0]);
|
|
SCWrite(pCon,pBueffel,eError);
|
|
return 0;
|
|
}
|
|
/* create a new one */
|
|
pNew = (pCaptureEntry)malloc(sizeof(CaptureEntry));
|
|
if(!pNew)
|
|
{
|
|
SICSLogWrite("Out of memory in LogCapture",eInternal);
|
|
return 0;
|
|
}
|
|
if(pCapture)
|
|
{
|
|
pCapture->pPrevious = pNew;
|
|
}
|
|
pNew->pPrevious = NULL;
|
|
pNew->pNext = pCapture;
|
|
pCapture = pNew;
|
|
pNew->iAllFlag = 0;
|
|
pNew->pCon = pCon;
|
|
pNew->iOut = i;
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
/*--------------------------------------------------------------------------*/
|
|
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) {
|
|
static char ts[80];
|
|
int hh, mm, ss;
|
|
struct timeval tv;
|
|
struct tm *time;
|
|
if (tp)
|
|
tv = *tp;
|
|
else
|
|
gettimeofday(&tv, NULL);
|
|
time = localtime(&tv.tv_sec);
|
|
hh = time->tm_hour;
|
|
mm = time->tm_min;
|
|
ss = time->tm_sec;
|
|
snprintf(ts, 80, "%02d:%02d:%02d.%06d", hh, mm, ss, (int) tv.tv_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;
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
int OpenVerifyLogFile()
|
|
{
|
|
char pFile[256];
|
|
char filnam[512];
|
|
char *pChar = NULL;
|
|
|
|
pChar = IFindOption(pSICSOptions,"LogFileBaseName");
|
|
if(!pChar)
|
|
{ /* Try to write to file "server" in*/
|
|
strcpy(pFile,"server");
|
|
}
|
|
else
|
|
{
|
|
strncpy(pFile,pChar,255);
|
|
}
|
|
snprintf(filnam,511,"%s%2.2d.log",pFile, iFile);
|
|
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;
|
|
}
|
|
/*---------------------------------------------------------------------------*/
|
|
void SICSLogWriteTime(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->iOut == eOut) || (pCurrent->iAllFlag == 1) )
|
|
{
|
|
NETWrite(pCurrent->pCon->pSock,pText,strlen(pText));
|
|
if (pText[text_len - 1] != '\n')
|
|
NETWrite(pCurrent->pCon->pSock, "\n", 1);
|
|
}
|
|
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();
|
|
}
|
|
|
|
/* switch file if too many lines */
|
|
if(iLineCount >= MAXLOG)
|
|
{
|
|
fprintf(fLogFile,"%s: <<<close logfile>>>\n", timestamp(NULL));
|
|
fclose(fLogFile);
|
|
fLogFile = NULL;
|
|
iFile++;
|
|
iLineCount = 0;
|
|
if(iFile >= MAXFILES)
|
|
{
|
|
iFile = 0;
|
|
}
|
|
iLogUsable = OpenVerifyLogFile();
|
|
}
|
|
|
|
if(1 == iLogUsable)
|
|
{
|
|
|
|
if (iLineCount == 0)
|
|
fprintf(fLogFile,"%s: <<<open logfile>>>\n", timestamp(NULL));
|
|
fprintf(fLogFile,"%s: ", timestamp(tp));
|
|
fprintf(fLogFile,"%s", pText);
|
|
if (text_len < 1 || pText[text_len - 1] != '\n')
|
|
fprintf(fLogFile,"\n");
|
|
fflush(fLogFile);
|
|
iLineCount++;
|
|
|
|
#if 0 /* Already done above */
|
|
/* do all captured as well */
|
|
pCurrent = pCapture;
|
|
while(pCurrent)
|
|
{
|
|
if( (pCurrent->iOut == eOut) || (pCurrent->iAllFlag == 1) )
|
|
{
|
|
NETWrite(pCurrent->pCon->pSock,pText,strlen(pText));
|
|
if (pText[text_len - 1] != '\n')
|
|
NETWrite(pCurrent->pCon->pSock, "\n", 1);
|
|
}
|
|
pCurrent = pCurrent->pNext;
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
|
|
void SICSLogWrite(char *pText, OutCode eOut) {
|
|
SICSLogWriteTime(pText, eOut, NULL);
|
|
}
|