]>
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 | #include <stdarg.h> |
7da203a3 | 28 | #include "update.h" |
29 | #include <krb.h> | |
36689901 | 30 | |
de56407f | 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[] = { | |
5eaef520 | 39 | LOG_DEBUG, |
40 | LOG_INFO, | |
41 | LOG_WARNING, | |
42 | LOG_ERR | |
de56407f | 43 | }; |
44 | #endif | |
7da203a3 | 45 | extern int log_priority; |
29ce7010 | 46 | extern char *whoami; |
de56407f | 47 | |
5eaef520 | 48 | void mr_update_com_err_hook(const char *whoami, long code, |
49 | const char *fmt, va_list args) | |
de56407f | 50 | { |
5eaef520 | 51 | char buf[BUFSIZ], *cp; |
52 | FILE _strbuf; | |
de56407f | 53 | |
54 | #ifndef use_syslog | |
5eaef520 | 55 | strcpy(buf, whoami); |
56 | for (cp = buf; *cp; cp++) | |
57 | ; | |
58 | *cp++ = ':'; | |
59 | *cp++ = ' '; | |
de56407f | 60 | #else |
5eaef520 | 61 | cp = buf; |
62 | *cp = '\0'; | |
de56407f | 63 | #endif |
5eaef520 | 64 | if (code) |
65 | { | |
66 | strcpy(cp, error_message(code)); | |
67 | while (*cp) | |
68 | cp++; | |
de56407f | 69 | } |
5eaef520 | 70 | vsprintf(cp, fmt, args); |
de56407f | 71 | #ifdef use_syslog |
5eaef520 | 72 | syslog(syslog_prio[log_priority], "%s", buf); |
de56407f | 73 | #endif |
74 | #ifdef use_tty | |
5eaef520 | 75 | puts(buf); |
de56407f | 76 | #endif |
77 | } | |
78 | ||
5eaef520 | 79 | mr_update_initialize(void) |
de56407f | 80 | { |
5eaef520 | 81 | static int initialized = 0; |
82 | if (initialized) | |
83 | return; | |
de56407f | 84 | #ifdef use_syslog |
5eaef520 | 85 | openlog(whoami, LOG_PID, LOG_DAEMON); |
de56407f | 86 | #endif |
5eaef520 | 87 | set_com_err_hook(mr_update_com_err_hook); |
88 | log_priority = log_INFO; | |
89 | initialized = 1; | |
de56407f | 90 | } |
29ce7010 | 91 | |
92 | ||
93 | static char fmt[] = "[%s] %s"; | |
94 | ||
5eaef520 | 95 | #define def(name, level, prio) \ |
96 | name(char *msg)\ | |
29ce7010 | 97 | {\ |
44d12d58 | 98 | int old_prio; \ |
5eaef520 | 99 | old_prio = log_priority; \ |
100 | mr_update_initialize(); \ | |
101 | com_err(whoami, 0, fmt, level, msg); \ | |
102 | log_priority = old_prio; \ | |
29ce7010 | 103 | } |
104 | ||
2ad0a777 | 105 | def(mr_log_error, "error", log_ERROR) |
106 | def(mr_log_warning, "warning", log_WARNING) | |
107 | def(mr_log_info, "info", log_INFO) | |
108 | def(mr_debug, "debug", log_DEBUG) |