1 /* $FreeBSD: src/libexec/bootpd/report.c,v 1.2.6.2 2001/03/05 10:58:59 kris Exp $ */
2 /* $DragonFly: src/libexec/bootpd/report.c,v 1.2 2003/06/17 04:27:07 dillon Exp $ */
5 * report() - calls syslog
28 #define LOG_BOOTP LOG_DAEMON
32 extern char *progname;
35 * This is initialized so you get stderr until you call
38 static int stderr_only = 1;
47 openlog(progname, LOG_PID | LOG_NDELAY, LOG_BOOTP);
53 * This routine reports errors and such via stderr and syslog() if
54 * appopriate. It just helps avoid a lot of "#ifdef SYSLOG" constructs
55 * from being scattered throughout the code.
57 * The syntax is identical to syslog(3), but %m is not considered special
58 * for output to stderr (i.e. you'll see "%m" in the output. . .). Also,
59 * control strings should normally end with \n since newlines aren't
60 * automatically generated for stderr output (whereas syslog strips out all
61 * newlines and adds its own at the end).
64 static char *levelnames[] = {
89 static int numlevels = sizeof(levelnames) / sizeof(levelnames[0]);
93 * Print a log message using syslog(3) and/or stderr.
94 * The message passed in should not include a newline.
98 report(int priority, const char *fmt,...)
102 report(priority, fmt, va_alist)
109 static char buf[128];
111 if ((priority < 0) || (priority >= numlevels)) {
112 priority = numlevels - 1;
119 vsnprintf(buf, sizeof(buf), fmt, ap);
125 if (stderr_only || (debug > 2)) {
126 fprintf(stderr, "%s: %s %s\n",
127 progname, levelnames[priority], buf);
131 syslog((priority | LOG_BOOTP), "%s", buf);
138 * Return pointer to static string which gives full filesystem error message.
143 return strerror(errno);
150 * c-argdecl-indent: 4
151 * c-continued-statement-offset: 4
152 * c-continued-brace-offset: -4