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