1 /* $FreeBSD: src/libexec/bootpd/report.c,v 1.2.6.2 2001/03/05 10:58:59 kris Exp $ */
4 * report() - calls syslog
27 #define LOG_BOOTP LOG_DAEMON
31 extern char *progname
;
34 * This is initialized so you get stderr until you call
37 static int stderr_only
= 1;
40 report_init(int nolog
)
45 openlog(progname
, LOG_PID
| LOG_NDELAY
, LOG_BOOTP
);
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 char *levelnames
[] = {
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.
96 report(int priority
, const char *fmt
,...)
100 report(priority
, fmt
, va_alist
)
107 static char buf
[128];
109 if ((priority
< 0) || (priority
>= numlevels
)) {
110 priority
= numlevels
- 1;
117 vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
123 if (stderr_only
|| (debug
> 2)) {
124 fprintf(stderr
, "%s: %s %s\n",
125 progname
, levelnames
[priority
], buf
);
129 syslog((priority
| LOG_BOOTP
), "%s", buf
);
136 * Return pointer to static string which gives full filesystem error message.
141 return strerror(errno
);