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 <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2006-09-07 00:06:50 +05:30
|
|
|
#include <syslog.h>
|
2001-03-20 00:54:06 +05:30
|
|
|
#include "libbb.h"
|
|
|
|
|
2006-09-07 00:06:50 +05:30
|
|
|
int logmode = LOGMODE_STDIO;
|
|
|
|
|
|
|
|
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)
|
|
|
|
fputc('\n', stderr);
|
|
|
|
else
|
|
|
|
fprintf(stderr, ": %s\n", strerr);
|
|
|
|
}
|
2006-09-07 11:32:39 +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
|
|
|
}
|