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