diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-06 22:36:50 +0400 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-06 22:36:50 +0400 |
commit | 3538b9a8822421b7c8596a33a917dcf2f99c92b7 (patch) | |
tree | 768c23fe79bb81583de7376a4d744632d888d303 /libbb | |
parent | 5d725462d44268f9a86030daaa6f6396d32f796c (diff) |
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')
-rw-r--r-- | libbb/Makefile.in | 1 | ||||
-rw-r--r-- | libbb/dump.c | 4 | ||||
-rw-r--r-- | libbb/error_msg.c | 3 | ||||
-rw-r--r-- | libbb/error_msg_and_die.c | 3 | ||||
-rw-r--r-- | libbb/inet_common.c | 2 | ||||
-rw-r--r-- | libbb/setup_environment.c | 5 | ||||
-rw-r--r-- | libbb/verror_msg.c | 34 | ||||
-rw-r--r-- | libbb/vherror_msg.c | 7 | ||||
-rw-r--r-- | libbb/vperror_msg.c | 6 | ||||
-rw-r--r-- | libbb/xfuncs.c | 2 |
10 files changed, 40 insertions, 27 deletions
diff --git a/libbb/Makefile.in b/libbb/Makefile.in index 05123e2af..7e84a6d62 100644 --- a/libbb/Makefile.in +++ b/libbb/Makefile.in @@ -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 \ diff --git a/libbb/dump.c b/libbb/dump.c index 28f745fb6..d76cbc0b7 100644 --- a/libbb/dump.c +++ b/libbb/dump.c @@ -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."); } } /* diff --git a/libbb/error_msg.c b/libbb/error_msg.c index a8ed4bf8e..b2141f3a2 100644 --- a/libbb/error_msg.c +++ b/libbb/error_msg.c @@ -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); } diff --git a/libbb/error_msg_and_die.c b/libbb/error_msg_and_die.c index 842260b0f..f25a1da32 100644 --- a/libbb/error_msg_and_die.c +++ b/libbb/error_msg_and_die.c @@ -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); } diff --git a/libbb/inet_common.c b/libbb/inet_common.c index 75a03fda4..ccf0c3511 100644 --- a/libbb/inet_common.c +++ b/libbb/inet_common.c @@ -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; diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c index dfab786d9..a14649625 100644 --- a/libbb/setup_environment.c +++ b/libbb/setup_environment.c @@ -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 ); } 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 @@ #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); } diff --git a/libbb/vherror_msg.c b/libbb/vherror_msg.c index cb5502176..7d9fc432a 100644 --- a/libbb/vherror_msg.c +++ b/libbb/vherror_msg.c @@ -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)); } diff --git a/libbb/vperror_msg.c b/libbb/vperror_msg.c index 5a854ec4a..70fd671e3 100644 --- a/libbb/vperror_msg.c +++ b/libbb/vperror_msg.c @@ -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)); } diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 850721e3e..4e407e45f 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c @@ -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 |