Implement optional syslog logging using ordinary

bb_xx_msg calls, and convert networking/* to it.
The rest of bbox will be converted gradually.
This commit is contained in:
Denis Vlasenko 2006-09-06 18:36:50 +00:00
parent 5d725462d4
commit 3538b9a882
39 changed files with 296 additions and 366 deletions

View file

@ -28,6 +28,7 @@ LIBBB-y:= \
restricted_shell.c run_parts.c run_shell.c safe_read.c safe_write.c \
safe_strncpy.c setup_environment.c sha1.c simplify_path.c \
trim.c u_signal_names.c vdprintf.c verror_msg.c \
info_msg.c vinfo_msg.c \
vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \
xgethostbyname.c xgethostbyname2.c xreadlink.c xgetlarg.c \
get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \

View file

@ -220,7 +220,7 @@ static void rewrite(FS * fs)
}
} else {
DO_BAD_CONV_CHAR:
bb_error_msg_and_die("bad conversion character %%%s.\n", p1);
bb_error_msg_and_die("bad conversion character %%%s.", p1);
}
/*
@ -253,7 +253,7 @@ static void rewrite(FS * fs)
/* only one conversion character if byte count */
if (!(pr->flags & F_ADDRESS) && fu->bcnt && nconv++) {
bb_error_msg_and_die("byte count with multiple conversion characters.\n");
bb_error_msg_and_die("byte count with multiple conversion characters.");
}
}
/*

View file

@ -18,7 +18,6 @@ void bb_error_msg(const char *s, ...)
va_list p;
va_start(p, s);
bb_verror_msg(s, p);
bb_verror_msg(s, p, NULL);
va_end(p);
putc('\n', stderr);
}

View file

@ -18,8 +18,7 @@ void bb_error_msg_and_die(const char *s, ...)
va_list p;
va_start(p, s);
bb_verror_msg(s, p);
bb_verror_msg(s, p, NULL);
va_end(p);
putc('\n', stderr);
exit(bb_default_error_retval);
}

View file

@ -205,7 +205,7 @@ int INET6_rresolve(char *name, size_t len, struct sockaddr_in6 *sin6,
/* Grmpf. -FvK */
if (sin6->sin6_family != AF_INET6) {
#ifdef DEBUG
bb_error_msg(_("rresolve: unsupport address family %d !\n"),
bb_error_msg(_("rresolve: unsupport address family %d!"),
sin6->sin6_family);
#endif
errno = EAFNOSUPPORT;

View file

@ -60,10 +60,7 @@ void setup_environment ( const char *shell, int loginshell, int changeenv, const
* Some systems default to HOME=/
*/
if ( chdir ( pw-> pw_dir )) {
if ( chdir ( "/" )) {
syslog ( LOG_WARNING, "unable to cd to %s' for user %s'\n", pw-> pw_dir, pw-> pw_name );
bb_error_msg_and_die ( "cannot cd to home directory or /" );
}
xchdir ( "/" );
fputs ( "warning: cannot change to home directory\n", stderr );
}

View file

@ -11,11 +11,37 @@
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <syslog.h>
#include "libbb.h"
void bb_verror_msg(const char *s, va_list p)
int logmode = LOGMODE_STDIO;
void bb_verror_msg(const char *s, va_list p, const char* strerr)
{
fflush(stdout);
fprintf(stderr, "%s: ", bb_applet_name);
vfprintf(stderr, s, p);
/* 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);
}
if (logmode & LOGMODE_SYSLOG) {
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);
}

View file

@ -16,10 +16,5 @@
void bb_vherror_msg(const char *s, va_list p)
{
if(s == 0)
s = "";
bb_verror_msg(s, p);
if (*s)
fputs(": ", stderr);
herror("");
bb_verror_msg(s, p, hstrerror(h_errno));
}

View file

@ -15,9 +15,5 @@
void bb_vperror_msg(const char *s, va_list p)
{
int err=errno;
if(s == 0) s = "";
bb_verror_msg(s, p);
if (*s) s = ": ";
fprintf(stderr, "%s%s\n", s, strerror(err));
bb_verror_msg(s, p, strerror(errno));
}

View file

@ -397,7 +397,7 @@ char *xasprintf(const char *format, ...)
va_end(p);
#endif
if (r < 0) bb_perror_msg_and_die("xasprintf");
if (r < 0) bb_error_msg_and_die(bb_msg_memory_exhausted);
return string_ptr;
}
#endif