2001-03-20 00:54:06 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* Utility routines.
|
|
|
|
*
|
2004-03-15 13:59:22 +05:30
|
|
|
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
2001-03-20 00:54:06 +05:30
|
|
|
*
|
2006-05-20 00:59:19 +05:30
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
2001-03-20 00:54:06 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libbb.h"
|
2006-09-12 18:57:55 +05:30
|
|
|
#include <syslog.h>
|
2001-03-20 00:54:06 +05:30
|
|
|
|
2006-09-07 00:06:50 +05:30
|
|
|
int logmode = LOGMODE_STDIO;
|
2006-09-07 21:50:03 +05:30
|
|
|
const char *msg_eol = "\n";
|
2006-09-07 00:06:50 +05:30
|
|
|
|
|
|
|
void bb_verror_msg(const char *s, va_list p, const char* strerr)
|
2001-03-20 00:54:06 +05:30
|
|
|
{
|
2006-09-07 00:06:50 +05:30
|
|
|
/* va_copy is used because it is not portable
|
|
|
|
* to use va_list p twice */
|
|
|
|
va_list p2;
|
|
|
|
va_copy(p2, p);
|
|
|
|
|
|
|
|
if (logmode & LOGMODE_STDIO) {
|
|
|
|
fflush(stdout);
|
|
|
|
fprintf(stderr, "%s: ", bb_applet_name);
|
|
|
|
vfprintf(stderr, s, p);
|
|
|
|
if (!strerr)
|
2006-09-07 21:50:03 +05:30
|
|
|
fputs(msg_eol, stderr);
|
2006-09-07 00:06:50 +05:30
|
|
|
else
|
2006-09-07 21:50:03 +05:30
|
|
|
fprintf(stderr, ": %s%s", strerr, msg_eol);
|
2006-09-07 00:06:50 +05:30
|
|
|
}
|
2006-09-07 21:33:45 +05:30
|
|
|
if (ENABLE_FEATURE_SYSLOG && (logmode & LOGMODE_SYSLOG)) {
|
2006-09-07 00:06:50 +05:30
|
|
|
if (!strerr)
|
|
|
|
vsyslog(LOG_ERR, s, p2);
|
|
|
|
else {
|
|
|
|
char *msg;
|
|
|
|
if (vasprintf(&msg, s, p2) < 0)
|
|
|
|
bb_error_msg_and_die(bb_msg_memory_exhausted);
|
|
|
|
syslog(LOG_ERR, "%s: %s", msg, strerr);
|
|
|
|
free(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
va_end(p2);
|
2001-03-20 00:54:06 +05:30
|
|
|
}
|