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;
41 report_init(int nolog
)
46 openlog(progname
, LOG_PID
| LOG_NDELAY
, LOG_BOOTP
);
52 * This routine reports errors and such via stderr and syslog() if
53 * appopriate. It just helps avoid a lot of "#ifdef SYSLOG" constructs
54 * from being scattered throughout the code.
56 * The syntax is identical to syslog(3), but %m is not considered special
57 * for output to stderr (i.e. you'll see "%m" in the output. . .). Also,
58 * control strings should normally end with \n since newlines aren't
59 * automatically generated for stderr output (whereas syslog strips out all
60 * newlines and adds its own at the end).
63 static char *levelnames
[] = {
88 static int numlevels
= sizeof(levelnames
) / sizeof(levelnames
[0]);
92 * Print a log message using syslog(3) and/or stderr.
93 * The message passed in should not include a newline.
97 report(int priority
, const char *fmt
,...)
101 report(priority
, fmt
, va_alist
)
108 static char buf
[128];
110 if ((priority
< 0) || (priority
>= numlevels
)) {
111 priority
= numlevels
- 1;
118 vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
124 if (stderr_only
|| (debug
> 2)) {
125 fprintf(stderr
, "%s: %s %s\n",
126 progname
, levelnames
[priority
], buf
);
130 syslog((priority
| LOG_BOOTP
), "%s", buf
);
137 * Return pointer to static string which gives full filesystem error message.
142 return strerror(errno
);
149 * c-argdecl-indent: 4
150 * c-continued-statement-offset: 4
151 * c-continued-brace-offset: -4