Expand PMF_FN_* macros.
[netbsd-mini2440.git] / usr.sbin / bootp / common / report.c
blob8de958fa61f439a682920260cd8b800653a09822
1 /* $NetBSD: report.c,v 1.6 2002/07/14 00:26:18 wiz Exp $ */
3 #include <sys/cdefs.h>
4 #ifndef lint
5 __RCSID("$NetBSD: report.c,v 1.6 2002/07/14 00:26:18 wiz Exp $");
6 #endif
8 /*
9 * report() - calls syslog
12 #include <stdarg.h>
14 #include <stdio.h>
15 #include <string.h>
16 #include <syslog.h>
18 #include "report.h"
20 #ifndef LOG_NDELAY
21 #define LOG_NDELAY 0
22 #endif
23 #ifndef LOG_DAEMON
24 #define LOG_DAEMON 0
25 #endif
26 #ifndef LOG_BOOTP
27 #define LOG_BOOTP LOG_DAEMON
28 #endif
30 extern int debug;
31 extern char *progname;
34 * This is initialized so you get stderr until you call
35 * report_init()
37 static int stderr_only = 1;
39 void
40 report_init(int nolog)
42 stderr_only = nolog;
43 #ifdef SYSLOG
44 if (!stderr_only) {
45 openlog(progname, LOG_PID | LOG_NDELAY, LOG_BOOTP);
47 #endif
51 * This routine reports errors and such via stderr and syslog() if
52 * appopriate. It just helps avoid a lot of "#ifdef SYSLOG" constructs
53 * from being scattered throughout the code.
55 * The syntax is identical to syslog(3), but %m is not considered special
56 * for output to stderr (i.e. you'll see "%m" in the output. . .). Also,
57 * control strings should normally end with \n since newlines aren't
58 * automatically generated for stderr output (whereas syslog strips out all
59 * newlines and adds its own at the end).
62 static const char *levelnames[] = {
63 #ifdef LOG_SALERT
64 "level(0): ",
65 "alert(1): ",
66 "alert(2): ",
67 "emerg(3): ",
68 "error(4): ",
69 "crit(5): ",
70 "warn(6): ",
71 "note(7): ",
72 "info(8): ",
73 "debug(9): ",
74 "level(?): "
75 #else
76 "emerg(0): ",
77 "alert(1): ",
78 "crit(2): ",
79 "error(3): ",
80 "warn(4): ",
81 "note(5): ",
82 "info(6): ",
83 "debug(7): ",
84 "level(?): "
85 #endif
87 static int numlevels = sizeof(levelnames) / sizeof(levelnames[0]);
91 * Print a log message using syslog(3) and/or stderr.
92 * The message passed in should not include a newline.
94 void
95 report(int priority, const char *fmt,...)
97 va_list ap;
98 static char buf[128];
100 if ((priority < 0) || (priority >= numlevels)) {
101 priority = numlevels - 1;
103 va_start(ap, fmt);
104 vsprintf(buf, fmt, ap);
105 va_end(ap);
108 * Print the message
110 if (stderr_only || (debug > 2)) {
111 fprintf(stderr, "%s: %s %s\n",
112 progname, levelnames[priority], buf);
114 #ifdef SYSLOG
115 if (!stderr_only)
116 syslog((priority | LOG_BOOTP), "%s", buf);
117 #endif
123 * Return pointer to static string which gives full filesystem error message.
125 const char *
126 get_errmsg(void)
128 extern int errno;
130 return strerror(errno);
134 * Local Variables:
135 * tab-width: 4
136 * c-indent-level: 4
137 * c-argdecl-indent: 4
138 * c-continued-statement-offset: 4
139 * c-continued-brace-offset: -4
140 * c-label-offset: -4
141 * c-brace-offset: 0
142 * End: