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