s/qmail 4.2.29a
Next generation secure email transport
Loading...
Searching...
No Matches
splogger.c
Go to the documentation of this file.
1#include <sys/types.h>
2#include <sys/time.h>
3#include <syslog.h>
4#include <unistd.h>
5#include "error.h"
6#include "buffer.h"
7#include "exit.h"
8#include "str.h"
9#include "scan.h"
10#include "fmt.h"
11
12char buf[800]; /* syslog truncates long lines (or crashes); GPACIC */
13int bufpos = 0; /* 0 <= bufpos < sizeof(buf) */
14int flagcont = 0;
15int priority; /* defined if flagcont */
16char stamp[FMT_ULONG + FMT_ULONG + 3]; /* defined if flagcont */
17
19{
20 struct timeval tv;
21 char *s;
22 gettimeofday(&tv,(struct timezone *) 0);
23 s = stamp;
24 s += fmt_ulong(s,(unsigned long) tv.tv_sec);
25 *s++ = '.';
26 s += fmt_uint0(s,(unsigned int) tv.tv_usec,6);
27 *s = 0;
28}
29
30void flush()
31{
32 if (bufpos) {
33 buf[bufpos] = 0;
34 if (flagcont)
35 syslog(priority,"%s+%s",stamp,buf); /* logger folds invisibly; GPACIC */
36 else {
37 stamp_make();
38 priority = LOG_INFO;
39 if (str_start(buf,"warning:")) priority = LOG_WARNING;
40 if (str_start(buf,"alert:")) priority = LOG_ALERT;
41 syslog(priority,"%s %s",stamp,buf);
42 flagcont = 1;
43 }
44 }
45 bufpos = 0;
46}
47
48int main(int argc,char **argv)
49{
50 char ch;
51
52 if (argv[1])
53 if (argv[2]) {
54 unsigned long facility;
55 scan_ulong(argv[2],&facility);
56 openlog(argv[1],0,facility << 3);
57 }
58 else
59 openlog(argv[1],0,LOG_MAIL);
60 else
61 openlog("splogger",0,LOG_MAIL);
62
63 for (;;) {
64 if (buffer_get(buffer_0,&ch,1) < 1) _exit(0);
65 if (ch == '\n') { flush(); flagcont = 0; continue; }
66 if (bufpos == sizeof(buf) - 1) flush();
67 if ((ch < 32) || (ch > 126)) ch = '?'; /* logger truncates at 0; GPACIC */
68 buf[bufpos++] = ch;
69 }
70}
int main()
Definition: chkshsgr.c:6
void _exit()
char buf[800]
Definition: splogger.c:12
char stamp[FMT_ULONG+FMT_ULONG+3]
Definition: splogger.c:16
int flagcont
Definition: splogger.c:14
int bufpos
Definition: splogger.c:13
int priority
Definition: splogger.c:15
void flush()
Definition: splogger.c:30
void stamp_make()
Definition: splogger.c:18