/* additional modifications by William Tan */ #ifndef O_NOT_LOG #include #include #include #include "error.h" #include "qsutil.h" #include "stralloc.h" #include "substdio.h" #include "subfd.h" #include "exit.h" #include "str.h" #include "scan.h" #include "fmt.h" /* declare a global dummy copy of the message to be logged */ static stralloc real_message = { 0 }; char fixedbuf[800]; /* syslog truncates long lines (or crashes); GPACIC */ int bufpos = 0; /* 0 <= bufpos < sizeof(buf) */ int flagcont = 0; int priority; /* defined if flagcont */ char stamp[FMT_ULONG + FMT_ULONG + 3]; /* defined if flagcont */ void stamp_make() { struct timeval tv; char *s; gettimeofday(&tv,(struct timezone *) 0); s = stamp; s += fmt_ulong(s,(unsigned long) tv.tv_sec); *s++ = '.'; s += fmt_uint0(s,(unsigned int) tv.tv_usec,6); *s = 0; } void splogflush() { if (bufpos) { fixedbuf[bufpos] = 0; if (flagcont) syslog(priority,"%s+%s",stamp,fixedbuf); /* logger folds invisibly; GPACIC */ else { stamp_make(); priority = LOG_INFO; if (str_start(fixedbuf,"warning:")) priority = LOG_WARNING; if (str_start(fixedbuf,"alert:")) priority = LOG_ALERT; syslog(priority,"%s %s",stamp,fixedbuf); flagcont = 1; } } bufpos = 0; } void splog(char *splogger, char *message) { int i; int max = sizeof(fixedbuf) - 1; while (! stralloc_copys(&real_message, message)) nomem(); if (! stralloc_0(&real_message)) nomem(); openlog(splogger, 0, LOG_MAIL); for (i = 0; real_message.s[i] != '\0' && i < max - 1; i++) { if (real_message.s[i] == '\n') { splogflush(); flagcont = 0; continue; } if (bufpos == max) splogflush(); if ((real_message.s[i] < 32) || (real_message.s[i] > 126)) real_message.s[i] = '?'; /* logger truncates at 0; GPACIC */ fixedbuf[bufpos++] = real_message.s[i]++; } if (bufpos < max) { i++; fixedbuf[bufpos++] = '\n'; splogflush(); } real_message.len = 0; closelog(); return; } #else void splog(char *splogger, char *message) { } #endif