1 /* $NetBSD: report.c,v 1.6 2002/07/14 00:26:18 wiz Exp $ */
5 __RCSID("$NetBSD: report.c,v 1.6 2002/07/14 00:26:18 wiz Exp $");
9 * 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 const 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.
95 report(int priority
, const char *fmt
,...)
100 if ((priority
< 0) || (priority
>= numlevels
)) {
101 priority
= numlevels
- 1;
104 vsprintf(buf
, fmt
, ap
);
110 if (stderr_only
|| (debug
> 2)) {
111 fprintf(stderr
, "%s: %s %s\n",
112 progname
, levelnames
[priority
], buf
);
116 syslog((priority
| LOG_BOOTP
), "%s", buf
);
123 * Return pointer to static string which gives full filesystem error message.
130 return strerror(errno
);
137 * c-argdecl-indent: 4
138 * c-continued-statement-offset: 4
139 * c-continued-brace-offset: -4