Expand PMF_FN_* macros.
[netbsd-mini2440.git] / usr.sbin / sup / source / log.c
blobf80203628fdb2e08ec7fac2273dfaa126658b9ce
1 /* $NetBSD: log.c,v 1.9 2007/12/20 20:17:52 christos Exp $ */
3 /*
4 * Copyright (c) 1992 Carnegie Mellon University
5 * All Rights Reserved.
7 * Permission to use, copy, modify and distribute this software and its
8 * documentation is hereby granted, provided that both the copyright
9 * notice and this permission notice appear in all copies of the
10 * software, derivative works or modified versions, and any portions
11 * thereof, and that both notices appear in supporting documentation.
13 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
14 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
15 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 * Carnegie Mellon requests users of this software to return to
19 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
20 * School of Computer Science
21 * Carnegie Mellon University
22 * Pittsburgh PA 15213-3890
24 * any improvements or extensions that they make and grant Carnegie Mellon
25 * the rights to redistribute these changes.
28 * Logging support for SUP
29 **********************************************************************
30 * HISTORY
31 * Revision 1.5 92/08/11 12:03:43 mrt
32 * Brad's delinting and variable argument list usage
33 * changes. Added copyright.
35 * Revision 1.3 89/08/15 15:30:37 bww
36 * Updated to use v*printf() in place of _doprnt().
37 * From "[89/04/19 mja]" at CMU.
38 * [89/08/15 bww]
40 * 27-Dec-87 Glenn Marcy (gm0w) at Carnegie-Mellon University
41 * Added check to allow logopen() to be called multiple times.
43 * 20-May-87 Glenn Marcy (gm0w) at Carnegie-Mellon University
44 * Created.
46 **********************************************************************
49 #include <stdio.h>
50 #include <sys/syslog.h>
51 #include "supcdefs.h"
52 #include "supextern.h"
53 #include "c.h"
55 static int opened = 0;
57 void
58 logopen(char *program)
60 if (opened)
61 return;
62 openlog(program, LOG_PID, LOG_DAEMON);
63 opened++;
66 void
67 logquit(int retval, const char *fmt, ...)
69 char buf[STRINGLENGTH];
70 va_list ap;
72 va_start(ap, fmt);
73 vsnprintf(buf, sizeof(buf), fmt, ap);
74 va_end(ap);
75 if (opened) {
76 syslog(LOG_ERR, "%s", buf);
77 closelog();
78 exit(retval);
80 quit(retval, "SUP: %s\n", buf);
83 void
84 logerr(const char *fmt, ...)
86 char buf[STRINGLENGTH];
87 va_list ap;
89 va_start(ap, fmt);
90 vsnprintf(buf, sizeof(buf), fmt, ap);
91 va_end(ap);
92 if (opened) {
93 syslog(LOG_ERR, "%s", buf);
94 return;
96 fprintf(stderr, "SUP: %s\n", buf);
97 (void) fflush(stderr);
100 void
101 loginfo(const char *fmt, ...)
103 char buf[STRINGLENGTH];
104 va_list ap;
106 va_start(ap, fmt);
107 vsnprintf(buf, sizeof(buf), fmt, ap);
108 va_end(ap);
109 if (opened) {
110 syslog(LOG_INFO, "%s", buf);
111 return;
113 printf("%s\n", buf);
114 (void) fflush(stdout);
116 #ifdef LIBWRAP
117 #include <tcpd.h>
118 #ifndef LIBWRAP_ALLOW_FACILITY
119 #define LIBWRAP_ALLOW_FACILITY LOG_AUTH
120 #endif
121 #ifndef LIBWRAP_ALLOW_SEVERITY
122 #define LIBWRAP_ALLOW_SEVERITY LOG_INFO
123 #endif
124 #ifndef LIBWRAP_DENY_FACILITY
125 #define LIBWRAP_DENY_FACILITY LOG_AUTH
126 #endif
127 #ifndef LIBWRAP_DENY_SEVERITY
128 #define LIBWRAP_DENY_SEVERITY LOG_WARNING
129 #endif
130 int allow_severity = LIBWRAP_ALLOW_FACILITY | LIBWRAP_ALLOW_SEVERITY;
131 int deny_severity = LIBWRAP_DENY_FACILITY | LIBWRAP_DENY_SEVERITY;
133 void
134 logdeny(const char *fmt, ...)
136 char buf[STRINGLENGTH];
137 va_list ap;
139 va_start(ap, fmt);
140 vsnprintf(buf, sizeof(buf), fmt, ap);
141 va_end(ap);
142 if (opened) {
143 syslog(deny_severity, "%s", buf);
144 return;
146 printf("%s\n", buf);
147 (void) fflush(stdout);
150 void
151 logallow(const char *fmt, ...)
153 char buf[STRINGLENGTH];
154 va_list ap;
156 va_start(ap, fmt);
157 vsnprintf(buf, sizeof(buf), fmt, ap);
158 va_end(ap);
159 if (opened) {
160 syslog(allow_severity, "%s", buf);
161 return;
163 printf("%s\n", buf);
164 (void) fflush(stdout);
166 #endif /* LIBWRAP */