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