aboutsummaryrefslogtreecommitdiff
path: root/libbb/verror_msg.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/verror_msg.c')
-rw-r--r--libbb/verror_msg.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/libbb/verror_msg.c b/libbb/verror_msg.c
new file mode 100644
index 000000000..0f018c517
--- /dev/null
+++ b/libbb/verror_msg.c
@@ -0,0 +1,46 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Utility routines.
4 *
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */
9
10#include "libbb.h"
11#include <syslog.h>
12
13int logmode = LOGMODE_STDIO;
14const char *msg_eol = "\n";
15
16void bb_verror_msg(const char *s, va_list p, const char* strerr)
17{
18 /* va_copy is used because it is not portable
19 * to use va_list p twice */
20 va_list p2;
21 va_copy(p2, p);
22
23 if (logmode & LOGMODE_STDIO) {
24 fflush(stdout);
25 fprintf(stderr, "%s: ", applet_name);
26 vfprintf(stderr, s, p);
27 if (!strerr)
28 fputs(msg_eol, stderr);
29 else
30 fprintf(stderr, "%s%s%s",
31 s ? ": " : "",
32 strerr, msg_eol);
33 }
34 if (ENABLE_FEATURE_SYSLOG && (logmode & LOGMODE_SYSLOG)) {
35 if (!strerr)
36 vsyslog(LOG_ERR, s, p2);
37 else {
38 char *msg;
39 if (vasprintf(&msg, s, p2) < 0)
40 bb_error_msg_and_die(bb_msg_memory_exhausted);
41 syslog(LOG_ERR, "%s: %s", msg, strerr);
42 free(msg);
43 }
44 }
45 va_end(p2);
46}