modprobe: add toggle switch config file option to disable binary index use
[mit.git] / logging.c
blobac15edd3c0c1e48737d0e0aa54c1bb4f4ac58b48
1 #define _GNU_SOURCE /* asprintf */
3 #include <stdlib.h>
4 #include <stdarg.h>
5 #include <stdio.h>
6 #include <syslog.h>
8 #include "logging.h"
10 /* Do we use syslog for messages or stderr? */
11 int logging = 0;
13 void message(const char *prefix, const char *fmt, va_list *arglist)
15 char *buf, *buf2;
17 vasprintf(&buf, fmt, *arglist);
18 asprintf(&buf2, "%s%s", prefix, buf);
20 if (logging)
21 syslog(LOG_NOTICE, "%s", buf2);
22 else
23 fprintf(stderr, "%s", buf2);
24 free(buf2);
25 free(buf);
28 int warned = 0;
29 void warn(const char *fmt, ...)
31 va_list arglist;
32 warned++;
33 va_start(arglist, fmt);
34 message("WARNING: ", fmt, &arglist);
35 va_end(arglist);
38 void fatal(const char *fmt, ...)
40 va_list arglist;
41 va_start(arglist, fmt);
42 message("FATAL: ", fmt, &arglist);
43 va_end(arglist);
44 exit(1);