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