aboutsummaryrefslogtreecommitdiff
path: root/libbb/verror_msg.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-09-06 18:36:50 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-09-06 18:36:50 +0000
commit3538b9a8822421b7c8596a33a917dcf2f99c92b7 (patch)
tree768c23fe79bb81583de7376a4d744632d888d303 /libbb/verror_msg.c
parent5d725462d44268f9a86030daaa6f6396d32f796c (diff)
downloadbusybox-w32-3538b9a8822421b7c8596a33a917dcf2f99c92b7.tar.gz
busybox-w32-3538b9a8822421b7c8596a33a917dcf2f99c92b7.tar.bz2
busybox-w32-3538b9a8822421b7c8596a33a917dcf2f99c92b7.zip
Implement optional syslog logging using ordinary
bb_xx_msg calls, and convert networking/* to it. The rest of bbox will be converted gradually.
Diffstat (limited to 'libbb/verror_msg.c')
-rw-r--r--libbb/verror_msg.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/libbb/verror_msg.c b/libbb/verror_msg.c
index d458a7b2c..237547d1d 100644
--- a/libbb/verror_msg.c
+++ b/libbb/verror_msg.c
@@ -11,11 +11,37 @@
11#include <errno.h> 11#include <errno.h>
12#include <string.h> 12#include <string.h>
13#include <stdlib.h> 13#include <stdlib.h>
14#include <syslog.h>
14#include "libbb.h" 15#include "libbb.h"
15 16
16void bb_verror_msg(const char *s, va_list p) 17int logmode = LOGMODE_STDIO;
18
19void bb_verror_msg(const char *s, va_list p, const char* strerr)
17{ 20{
18 fflush(stdout); 21 /* va_copy is used because it is not portable
19 fprintf(stderr, "%s: ", bb_applet_name); 22 * to use va_list p twice */
20 vfprintf(stderr, s, p); 23 va_list p2;
24 va_copy(p2, p);
25
26 if (logmode & LOGMODE_STDIO) {
27 fflush(stdout);
28 fprintf(stderr, "%s: ", bb_applet_name);
29 vfprintf(stderr, s, p);
30 if (!strerr)
31 fputc('\n', stderr);
32 else
33 fprintf(stderr, ": %s\n", strerr);
34 }
35 if (logmode & LOGMODE_SYSLOG) {
36 if (!strerr)
37 vsyslog(LOG_ERR, s, p2);
38 else {
39 char *msg;
40 if (vasprintf(&msg, s, p2) < 0)
41 bb_error_msg_and_die(bb_msg_memory_exhausted);
42 syslog(LOG_ERR, "%s: %s", msg, strerr);
43 free(msg);
44 }
45 }
46 va_end(p2);
21} 47}