]>
Commit | Line | Data |
---|---|---|
de56407f | 1 | /* |
2 | * $Source$ | |
3 | * $Header$ | |
4 | */ | |
546bc43b | 5 | /* (c) Copyright 1988 by the Massachusetts Institute of Technology. */ |
6 | /* For copying and distribution information, please see the file */ | |
7 | /* <mit-copyright.h>. */ | |
de56407f | 8 | |
9 | #ifndef lint | |
10 | static char *rcsid_log_c = "$Header$"; | |
7da203a3 | 11 | #endif |
de56407f | 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 | */ | |
de56407f | 23 | |
546bc43b | 24 | #include <mit-copyright.h> |
de56407f | 25 | #include <stdio.h> |
26 | #include "com_err.h" | |
7da203a3 | 27 | #ifdef __STDC__ |
28 | #include <stdarg.h> | |
29 | #else | |
de56407f | 30 | #include <varargs.h> |
36689901 | 31 | #define const |
32 | #endif | |
7da203a3 | 33 | #include "update.h" |
34 | #include <krb.h> | |
36689901 | 35 | |
de56407f | 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 | |
7da203a3 | 50 | extern int log_priority; |
29ce7010 | 51 | extern char *whoami; |
de56407f | 52 | |
2ad0a777 | 53 | void mr_update_com_err_hook(whoami, code, fmt, args) |
36689901 | 54 | const char *whoami; |
55 | long code; | |
56 | const char *fmt; | |
de56407f | 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 | } | |
16a16c3e | 77 | #ifdef HAS_VSPRINTF |
2ad0a777 | 78 | vsprintf(cp, fmt, args); |
79 | #else | |
de56407f | 80 | _strbuf._flag = _IOWRT+_IOSTRG; |
81 | _strbuf._ptr = cp; | |
82 | _strbuf._cnt = BUFSIZ-(cp-buf); | |
83 | _doprnt(fmt, args, &_strbuf); | |
84 | putc('\0', &_strbuf); | |
2ad0a777 | 85 | #endif |
de56407f | 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 | ||
2ad0a777 | 94 | mr_update_initialize() |
de56407f | 95 | { |
96 | static int initialized = 0; | |
97 | if (initialized) | |
98 | return; | |
99 | #ifdef use_syslog | |
100 | openlog(whoami, LOG_PID, LOG_DAEMON); | |
101 | #endif | |
2ad0a777 | 102 | (void) set_com_err_hook(mr_update_com_err_hook); |
de56407f | 103 | log_priority = log_INFO; |
104 | initialized = 1; | |
105 | } | |
29ce7010 | 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; \ | |
2ad0a777 | 116 | mr_update_initialize(); \ |
29ce7010 | 117 | com_err(whoami, 0, fmt, level, msg); \ |
118 | log_priority = old_prio; \ | |
119 | } | |
120 | ||
2ad0a777 | 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) |