]> andersk Git - moira.git/blob - update/log.c
fix lint problems with new com_err library
[moira.git] / update / log.c
1 /*
2  *      $Source$
3  *      $Header$
4  */
5 /*  (c) Copyright 1988 by the Massachusetts Institute of Technology. */
6 /*  For copying and distribution information, please see the file */
7 /*  <mit-copyright.h>. */
8
9 #ifndef lint
10 static char *rcsid_log_c = "$Header$";
11 #endif  lint
12
13 /*
14  * handle logging for dcm and update server
15  *
16  * this should eventually use zephyr
17  */
18
19 /*
20  * define syslog for using syslog,
21  * default to tty
22  */
23
24 #include <mit-copyright.h>
25 #include <stdio.h>
26 #include "com_err.h"
27 #include <varargs.h>
28 #include "update.h"
29 #include <krb.h>
30
31 #ifndef __STDC__
32 #define const
33 #endif
34
35 #ifdef use_syslog
36 #include <syslog.h>
37 #else
38 #define use_tty
39 #endif
40
41 #ifdef use_syslog
42 int syslog_prio[] = {
43     LOG_DEBUG,
44     LOG_INFO,
45     LOG_WARNING,
46     LOG_ERR
47 };
48 #endif
49 int log_priority;
50 extern char *whoami;
51
52 void sms_update_com_err_hook(whoami, code, fmt, args)
53     const char *whoami;
54     long code;
55     const char *fmt;
56     va_list args;
57 {
58     char buf[BUFSIZ], *cp;
59     FILE _strbuf;
60
61 #ifndef use_syslog
62     strcpy(buf, whoami);
63     for (cp = buf; *cp; cp++)
64         ;
65     *cp++ = ':';
66     *cp++ = ' ';
67 #else
68     cp = buf;
69     *cp = '\0';
70 #endif
71     if (code) {
72         strcpy(cp, error_message(code));
73         while (*cp)
74             cp++;
75     }
76     _strbuf._flag = _IOWRT+_IOSTRG;
77     _strbuf._ptr = cp;
78     _strbuf._cnt = BUFSIZ-(cp-buf);
79     _doprnt(fmt, args, &_strbuf);
80     putc('\0', &_strbuf);
81 #ifdef use_syslog
82     syslog(syslog_prio[log_priority], "%s", buf);
83 #endif
84 #ifdef use_tty
85     puts(buf);
86 #endif
87 }
88
89 sms_update_initialize()
90 {
91     static int initialized = 0;
92     if (initialized)
93         return;
94 #ifdef use_syslog
95     openlog(whoami, LOG_PID, LOG_DAEMON);
96 #endif
97     (void) set_com_err_hook(sms_update_com_err_hook);
98     log_priority = log_INFO;
99     initialized = 1;
100 }
101
102
103 static char fmt[] = "[%s] %s";
104
105 #define def(name,level,prio) \
106     name(msg) \
107     char *msg; \
108 {\
109      register int old_prio; \
110      old_prio = log_priority; \
111      sms_update_initialize(); \
112      com_err(whoami, 0, fmt, level, msg); \
113      log_priority = old_prio; \
114 }
115
116 def(sms_log_error, "error", log_ERROR)
117 def(sms_log_warning, "warning", log_WARNING)
118 def(sms_log_info, "info", log_INFO)
119 def(sms_debug, "debug", log_DEBUG)
This page took 0.05351 seconds and 5 git commands to generate.