]> andersk Git - moira.git/blob - update/log.c
Fixes to build with `gcc' instead of `gcc -traditional' on suns. (Needed
[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
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 #ifdef __STDC__
28 #include <stdarg.h>
29 #else
30 #include <varargs.h>
31 #define const
32 #endif
33 #include "update.h"
34 #include <krb.h>
35
36 #ifdef use_syslog
37 #include <syslog.h>
38 #else
39 #define use_tty
40 #endif
41
42 #ifdef use_syslog
43 int syslog_prio[] = {
44     LOG_DEBUG,
45     LOG_INFO,
46     LOG_WARNING,
47     LOG_ERR
48 };
49 #endif
50 extern int log_priority;
51 extern char *whoami;
52
53 void mr_update_com_err_hook(whoami, code, fmt, args)
54     const char *whoami;
55     long code;
56     const char *fmt;
57     va_list args;
58 {
59     char buf[BUFSIZ], *cp;
60     FILE _strbuf;
61
62 #ifndef use_syslog
63     strcpy(buf, whoami);
64     for (cp = buf; *cp; cp++)
65         ;
66     *cp++ = ':';
67     *cp++ = ' ';
68 #else
69     cp = buf;
70     *cp = '\0';
71 #endif
72     if (code) {
73         strcpy(cp, error_message(code));
74         while (*cp)
75             cp++;
76     }
77 #ifdef HAS_VSPRINTF
78     vsprintf(cp, fmt, args);
79 #else
80     _strbuf._flag = _IOWRT+_IOSTRG;
81     _strbuf._ptr = cp;
82     _strbuf._cnt = BUFSIZ-(cp-buf);
83     _doprnt(fmt, args, &_strbuf);
84     putc('\0', &_strbuf);
85 #endif
86 #ifdef use_syslog
87     syslog(syslog_prio[log_priority], "%s", buf);
88 #endif
89 #ifdef use_tty
90     puts(buf);
91 #endif
92 }
93
94 mr_update_initialize()
95 {
96     static int initialized = 0;
97     if (initialized)
98         return;
99 #ifdef use_syslog
100     openlog(whoami, LOG_PID, LOG_DAEMON);
101 #endif
102     (void) set_com_err_hook(mr_update_com_err_hook);
103     log_priority = log_INFO;
104     initialized = 1;
105 }
106
107
108 static char fmt[] = "[%s] %s";
109
110 #define def(name,level,prio) \
111     name(msg) \
112     char *msg; \
113 {\
114      register int old_prio; \
115      old_prio = log_priority; \
116      mr_update_initialize(); \
117      com_err(whoami, 0, fmt, level, msg); \
118      log_priority = old_prio; \
119 }
120
121 def(mr_log_error, "error", log_ERROR)
122 def(mr_log_warning, "warning", log_WARNING)
123 def(mr_log_info, "info", log_INFO)
124 def(mr_debug, "debug", log_DEBUG)
This page took 0.505585 seconds and 5 git commands to generate.