aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-09-06 18:36:50 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-09-06 18:36:50 +0000
commit3538b9a8822421b7c8596a33a917dcf2f99c92b7 (patch)
tree768c23fe79bb81583de7376a4d744632d888d303 /libbb
parent5d725462d44268f9a86030daaa6f6396d32f796c (diff)
downloadbusybox-w32-3538b9a8822421b7c8596a33a917dcf2f99c92b7.tar.gz
busybox-w32-3538b9a8822421b7c8596a33a917dcf2f99c92b7.tar.bz2
busybox-w32-3538b9a8822421b7c8596a33a917dcf2f99c92b7.zip
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.in1
-rw-r--r--libbb/dump.c4
-rw-r--r--libbb/error_msg.c3
-rw-r--r--libbb/error_msg_and_die.c3
-rw-r--r--libbb/inet_common.c2
-rw-r--r--libbb/setup_environment.c5
-rw-r--r--libbb/verror_msg.c34
-rw-r--r--libbb/vherror_msg.c7
-rw-r--r--libbb/vperror_msg.c6
-rw-r--r--libbb/xfuncs.c2
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:= \
28 restricted_shell.c run_parts.c run_shell.c safe_read.c safe_write.c \ 28 restricted_shell.c run_parts.c run_shell.c safe_read.c safe_write.c \
29 safe_strncpy.c setup_environment.c sha1.c simplify_path.c \ 29 safe_strncpy.c setup_environment.c sha1.c simplify_path.c \
30 trim.c u_signal_names.c vdprintf.c verror_msg.c \ 30 trim.c u_signal_names.c vdprintf.c verror_msg.c \
31 info_msg.c vinfo_msg.c \
31 vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \ 32 vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \
32 xgethostbyname.c xgethostbyname2.c xreadlink.c xgetlarg.c \ 33 xgethostbyname.c xgethostbyname2.c xreadlink.c xgetlarg.c \
33 get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \ 34 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)
220 } 220 }
221 } else { 221 } else {
222 DO_BAD_CONV_CHAR: 222 DO_BAD_CONV_CHAR:
223 bb_error_msg_and_die("bad conversion character %%%s.\n", p1); 223 bb_error_msg_and_die("bad conversion character %%%s.", p1);
224 } 224 }
225 225
226 /* 226 /*
@@ -253,7 +253,7 @@ static void rewrite(FS * fs)
253 253
254 /* only one conversion character if byte count */ 254 /* only one conversion character if byte count */
255 if (!(pr->flags & F_ADDRESS) && fu->bcnt && nconv++) { 255 if (!(pr->flags & F_ADDRESS) && fu->bcnt && nconv++) {
256 bb_error_msg_and_die("byte count with multiple conversion characters.\n"); 256 bb_error_msg_and_die("byte count with multiple conversion characters.");
257 } 257 }
258 } 258 }
259 /* 259 /*
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, ...)
18 va_list p; 18 va_list p;
19 19
20 va_start(p, s); 20 va_start(p, s);
21 bb_verror_msg(s, p); 21 bb_verror_msg(s, p, NULL);
22 va_end(p); 22 va_end(p);
23 putc('\n', stderr);
24} 23}
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, ...)
18 va_list p; 18 va_list p;
19 19
20 va_start(p, s); 20 va_start(p, s);
21 bb_verror_msg(s, p); 21 bb_verror_msg(s, p, NULL);
22 va_end(p); 22 va_end(p);
23 putc('\n', stderr);
24 exit(bb_default_error_retval); 23 exit(bb_default_error_retval);
25} 24}
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,
205 /* Grmpf. -FvK */ 205 /* Grmpf. -FvK */
206 if (sin6->sin6_family != AF_INET6) { 206 if (sin6->sin6_family != AF_INET6) {
207#ifdef DEBUG 207#ifdef DEBUG
208 bb_error_msg(_("rresolve: unsupport address family %d !\n"), 208 bb_error_msg(_("rresolve: unsupport address family %d!"),
209 sin6->sin6_family); 209 sin6->sin6_family);
210#endif 210#endif
211 errno = EAFNOSUPPORT; 211 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
60 * Some systems default to HOME=/ 60 * Some systems default to HOME=/
61 */ 61 */
62 if ( chdir ( pw-> pw_dir )) { 62 if ( chdir ( pw-> pw_dir )) {
63 if ( chdir ( "/" )) { 63 xchdir ( "/" );
64 syslog ( LOG_WARNING, "unable to cd to %s' for user %s'\n", pw-> pw_dir, pw-> pw_name );
65 bb_error_msg_and_die ( "cannot cd to home directory or /" );
66 }
67 fputs ( "warning: cannot change to home directory\n", stderr ); 64 fputs ( "warning: cannot change to home directory\n", stderr );
68 } 65 }
69 66
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 @@
11#include <errno.h> 11#include <errno.h>
12#include <string.h> 12#include <string.h>
13#include <stdlib.h> 13#include <stdlib.h>
14#include <syslog.h>
14#include "libbb.h" 15#include "libbb.h"
15 16
16void bb_verror_msg(const char *s, va_list p) 17int logmode = LOGMODE_STDIO;
18
19void bb_verror_msg(const char *s, va_list p, const char* strerr)
17{ 20{
18 fflush(stdout); 21 /* va_copy is used because it is not portable
19 fprintf(stderr, "%s: ", bb_applet_name); 22 * to use va_list p twice */
20 vfprintf(stderr, s, p); 23 va_list p2;
24 va_copy(p2, p);
25
26 if (logmode & LOGMODE_STDIO) {
27 fflush(stdout);
28 fprintf(stderr, "%s: ", bb_applet_name);
29 vfprintf(stderr, s, p);
30 if (!strerr)
31 fputc('\n', stderr);
32 else
33 fprintf(stderr, ": %s\n", strerr);
34 }
35 if (logmode & LOGMODE_SYSLOG) {
36 if (!strerr)
37 vsyslog(LOG_ERR, s, p2);
38 else {
39 char *msg;
40 if (vasprintf(&msg, s, p2) < 0)
41 bb_error_msg_and_die(bb_msg_memory_exhausted);
42 syslog(LOG_ERR, "%s: %s", msg, strerr);
43 free(msg);
44 }
45 }
46 va_end(p2);
21} 47}
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 @@
16 16
17void bb_vherror_msg(const char *s, va_list p) 17void bb_vherror_msg(const char *s, va_list p)
18{ 18{
19 if(s == 0) 19 bb_verror_msg(s, p, hstrerror(h_errno));
20 s = "";
21 bb_verror_msg(s, p);
22 if (*s)
23 fputs(": ", stderr);
24 herror("");
25} 20}
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 @@
15 15
16void bb_vperror_msg(const char *s, va_list p) 16void bb_vperror_msg(const char *s, va_list p)
17{ 17{
18 int err=errno; 18 bb_verror_msg(s, p, strerror(errno));
19 if(s == 0) s = "";
20 bb_verror_msg(s, p);
21 if (*s) s = ": ";
22 fprintf(stderr, "%s%s\n", s, strerror(err));
23} 19}
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, ...)
397 va_end(p); 397 va_end(p);
398#endif 398#endif
399 399
400 if (r < 0) bb_perror_msg_and_die("xasprintf"); 400 if (r < 0) bb_error_msg_and_die(bb_msg_memory_exhausted);
401 return string_ptr; 401 return string_ptr;
402} 402}
403#endif 403#endif