aboutsummaryrefslogtreecommitdiff
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
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.
-rw-r--r--include/libbb.h13
-rw-r--r--include/usage.h2
-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
-rw-r--r--networking/fakeidentd.c7
-rw-r--r--networking/httpd.c2
-rw-r--r--networking/inetd.c141
-rw-r--r--networking/ipcalc.c4
-rw-r--r--networking/libiproute/iproute.c2
-rw-r--r--networking/nameif.c42
-rw-r--r--networking/telnetd.c24
-rw-r--r--networking/traceroute.c8
-rw-r--r--networking/udhcp/arpping.c12
-rw-r--r--networking/udhcp/clientpacket.c27
-rw-r--r--networking/udhcp/clientsocket.c6
-rw-r--r--networking/udhcp/common.c71
-rw-r--r--networking/udhcp/common.h18
-rw-r--r--networking/udhcp/dhcpc.c42
-rw-r--r--networking/udhcp/dhcpd.c32
-rw-r--r--networking/udhcp/files.c19
-rw-r--r--networking/udhcp/leases.c2
-rw-r--r--networking/udhcp/libbb_udhcp.h1
-rw-r--r--networking/udhcp/options.c13
-rw-r--r--networking/udhcp/packet.c14
-rw-r--r--networking/udhcp/pidfile.c2
-rw-r--r--networking/udhcp/script.c4
-rw-r--r--networking/udhcp/serverpacket.c20
-rw-r--r--networking/udhcp/signalpipe.c2
-rw-r--r--networking/udhcp/socket.c18
-rw-r--r--networking/vconfig.c2
-rw-r--r--networking/zcip.c45
39 files changed, 296 insertions, 366 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 404ff2e7a..c6a9ae577 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -112,6 +112,14 @@ extern void *llist_pop(llist_t **elm);
112extern void llist_free(llist_t *elm, void (*freeit)(void *data)); 112extern void llist_free(llist_t *elm, void (*freeit)(void *data));
113 113
114 114
115enum {
116 LOGMODE_NONE = 0,
117 LOGMODE_STDIO = 1<<0,
118 LOGMODE_SYSLOG = 1<<1,
119 LOGMODE_BOTH = LOGMODE_SYSLOG + LOGMODE_STDIO,
120};
121extern int logmode;
122
115extern void bb_show_usage(void) ATTRIBUTE_NORETURN ATTRIBUTE_EXTERNALLY_VISIBLE; 123extern void bb_show_usage(void) ATTRIBUTE_NORETURN ATTRIBUTE_EXTERNALLY_VISIBLE;
116extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); 124extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
117extern void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); 125extern void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
@@ -124,9 +132,12 @@ extern void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn,
124extern void bb_perror_nomsg_and_die(void) ATTRIBUTE_NORETURN; 132extern void bb_perror_nomsg_and_die(void) ATTRIBUTE_NORETURN;
125extern void bb_perror_nomsg(void); 133extern void bb_perror_nomsg(void);
126 134
135extern void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
136
127/* These two are used internally -- you shouldn't need to use them */ 137/* These two are used internally -- you shouldn't need to use them */
128extern void bb_verror_msg(const char *s, va_list p) __attribute__ ((format (printf, 1, 0))); 138extern void bb_verror_msg(const char *s, va_list p, const char *strerr) __attribute__ ((format (printf, 1, 0)));
129extern void bb_vperror_msg(const char *s, va_list p) __attribute__ ((format (printf, 1, 0))); 139extern void bb_vperror_msg(const char *s, va_list p) __attribute__ ((format (printf, 1, 0)));
140extern void bb_vinfo_msg(const char *s, va_list p) __attribute__ ((format (printf, 1, 0)));
130 141
131extern int bb_echo(int argc, char** argv); 142extern int bb_echo(int argc, char** argv);
132extern int bb_test(int argc, char** argv); 143extern int bb_test(int argc, char** argv);
diff --git a/include/usage.h b/include/usage.h
index 0f56507ce..a1ba0a282 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -2092,7 +2092,7 @@ USE_FEATURE_MDEV_CONFIG( \
2092#define nameif_trivial_usage \ 2092#define nameif_trivial_usage \
2093 "[-s] [-c FILE] [{IFNAME MACADDR}]" 2093 "[-s] [-c FILE] [{IFNAME MACADDR}]"
2094#define nameif_full_usage \ 2094#define nameif_full_usage \
2095 "Nameif renaming network interface while it in the down state.\n\n" \ 2095 "Nameif renames network interface while it in the down state.\n\n" \
2096 "Options:\n" \ 2096 "Options:\n" \
2097 "\t-c FILE\t\tUse configuration file (default is /etc/mactab)\n" \ 2097 "\t-c FILE\t\tUse configuration file (default is /etc/mactab)\n" \
2098 "\t-s\t\tUse syslog (LOCAL0 facility)\n" \ 2098 "\t-s\t\tUse syslog (LOCAL0 facility)\n" \
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
diff --git a/networking/fakeidentd.c b/networking/fakeidentd.c
index 29e09d13e..2d690edba 100644
--- a/networking/fakeidentd.c
+++ b/networking/fakeidentd.c
@@ -157,7 +157,6 @@ static int godaemon(void)
157 157
158 setsid(); 158 setsid();
159 159
160 openlog(bb_applet_name, 0, LOG_DAEMON);
161 return 1; 160 return 1;
162 } 161 }
163 162
@@ -219,6 +218,10 @@ static int checkInput(char *buf, int len, int l)
219 218
220int fakeidentd_main(int argc, char **argv) 219int fakeidentd_main(int argc, char **argv)
221{ 220{
221 /* This applet is an inetd-style daemon */
222 openlog(bb_applet_name, 0, LOG_DAEMON);
223 logmode = LOGMODE_SYSLOG;
224
222 memset(conns, 0, sizeof(conns)); 225 memset(conns, 0, sizeof(conns));
223 memset(&G, 0, sizeof(G)); 226 memset(&G, 0, sizeof(G));
224 FD_ZERO(&G.readfds); 227 FD_ZERO(&G.readfds);
@@ -286,7 +289,7 @@ deleteconn:
286 289
287 if (s < 0) { 290 if (s < 0) {
288 if (errno != EINTR) /* EINTR */ 291 if (errno != EINTR) /* EINTR */
289 syslog(LOG_ERR, "accept: %s", strerror(errno)); 292 bb_perror_msg("accept");
290 } else { 293 } else {
291 if (G.conncnt == MAXCONNS) 294 if (G.conncnt == MAXCONNS)
292 i = closeOldest(); 295 i = closeOldest();
diff --git a/networking/httpd.c b/networking/httpd.c
index 8852cbb62..9a8fc685a 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -1809,7 +1809,7 @@ static int miniHttpd(int server)
1809 config->rmt_ip & 0xff); 1809 config->rmt_ip & 0xff);
1810 config->port = ntohs(fromAddr.sin_port); 1810 config->port = ntohs(fromAddr.sin_port);
1811#if DEBUG 1811#if DEBUG
1812 bb_error_msg("connection from IP=%s, port %u\n", 1812 bb_error_msg("connection from IP=%s, port %u",
1813 config->rmt_ip_str, config->port); 1813 config->rmt_ip_str, config->port);
1814#endif 1814#endif
1815#endif /* CONFIG_FEATURE_HTTPD_CGI */ 1815#endif /* CONFIG_FEATURE_HTTPD_CGI */
diff --git a/networking/inetd.c b/networking/inetd.c
index 9947f01ae..e47022350 100644
--- a/networking/inetd.c
+++ b/networking/inetd.c
@@ -311,18 +311,19 @@ static FILE *fconfig;
311static char line[1024]; 311static char line[1024];
312static char *defhost; 312static char *defhost;
313 313
314static char *newstr (char *cp) 314/* xstrdup(NULL) returns NULL, but this one
315 * will return newly-allocated "" if called with NULL arg
316 * TODO: audit whether this makes any real difference
317 */
318static char *xxstrdup (char *cp)
315{ 319{
316 if ((cp = strdup (cp ? cp : ""))) 320 return xstrdup (cp ? cp : "");
317 return (cp);
318 syslog (LOG_ERR, "strdup: %m");
319 exit (1);
320} 321}
321 322
322static int setconfig (void) 323static int setconfig (void)
323{ 324{
324 free (defhost); 325 free (defhost);
325 defhost = newstr ("*"); 326 defhost = xstrdup ("*");
326 if (fconfig != NULL) { 327 if (fconfig != NULL) {
327 fseek (fconfig, 0L, SEEK_SET); 328 fseek (fconfig, 0L, SEEK_SET);
328 return (1); 329 return (1);
@@ -350,12 +351,12 @@ static void register_rpc (servtab_t *sep)
350 socklen_t size; 351 socklen_t size;
351 352
352 if ((pp = getprotobyname (sep->se_proto + 4)) == NULL) { 353 if ((pp = getprotobyname (sep->se_proto + 4)) == NULL) {
353 syslog (LOG_ERR, "%s: getproto: %m", sep->se_proto); 354 bb_perror_msg ("%s: getproto", sep->se_proto);
354 return; 355 return;
355 } 356 }
356 size = sizeof ir_sin; 357 size = sizeof ir_sin;
357 if (getsockname (sep->se_fd, (struct sockaddr *) &ir_sin, &size) < 0) { 358 if (getsockname (sep->se_fd, (struct sockaddr *) &ir_sin, &size) < 0) {
358 syslog (LOG_ERR, "%s/%s: getsockname: %m", 359 bb_perror_msg ("%s/%s: getsockname",
359 sep->se_service, sep->se_proto); 360 sep->se_service, sep->se_proto);
360 return; 361 return;
361 } 362 }
@@ -363,7 +364,7 @@ static void register_rpc (servtab_t *sep)
363 for (n = sep->se_rpcversl; n <= sep->se_rpcversh; n++) { 364 for (n = sep->se_rpcversl; n <= sep->se_rpcversh; n++) {
364 (void) pmap_unset (sep->se_rpcprog, n); 365 (void) pmap_unset (sep->se_rpcprog, n);
365 if (!pmap_set (sep->se_rpcprog, n, pp->p_proto, ntohs (ir_sin.sin_port))) 366 if (!pmap_set (sep->se_rpcprog, n, pp->p_proto, ntohs (ir_sin.sin_port)))
366 syslog (LOG_ERR, "%s %s: pmap_set: %u %u %u %u: %m", 367 bb_perror_msg ("%s %s: pmap_set: %u %u %u %u",
367 sep->se_service, sep->se_proto, 368 sep->se_service, sep->se_proto,
368 sep->se_rpcprog, n, pp->p_proto, ntohs (ir_sin.sin_port)); 369 sep->se_rpcprog, n, pp->p_proto, ntohs (ir_sin.sin_port));
369 } 370 }
@@ -375,7 +376,7 @@ static void unregister_rpc (servtab_t *sep)
375 376
376 for (n = sep->se_rpcversl; n <= sep->se_rpcversh; n++) { 377 for (n = sep->se_rpcversl; n <= sep->se_rpcversh; n++) {
377 if (!pmap_unset (sep->se_rpcprog, n)) 378 if (!pmap_unset (sep->se_rpcprog, n))
378 syslog (LOG_ERR, "pmap_unset(%u, %u)", sep->se_rpcprog, n); 379 bb_error_msg ("pmap_unset(%u, %u)", sep->se_rpcprog, n);
379 } 380 }
380} 381}
381#endif /* CONFIG_FEATURE_INETD_RPC */ 382#endif /* CONFIG_FEATURE_INETD_RPC */
@@ -401,19 +402,19 @@ static int bump_nofile (void)
401 struct rlimit rl; 402 struct rlimit rl;
402 403
403 if (getrlimit (RLIMIT_NOFILE, &rl) < 0) { 404 if (getrlimit (RLIMIT_NOFILE, &rl) < 0) {
404 syslog (LOG_ERR, "getrlimit: %m"); 405 bb_perror_msg ("getrlimit");
405 return -1; 406 return -1;
406 } 407 }
407 rl.rlim_cur = MIN (rl.rlim_max, rl.rlim_cur + FD_CHUNK); 408 rl.rlim_cur = MIN (rl.rlim_max, rl.rlim_cur + FD_CHUNK);
408 rl.rlim_cur = MIN (FD_SETSIZE, rl.rlim_cur + FD_CHUNK); 409 rl.rlim_cur = MIN (FD_SETSIZE, rl.rlim_cur + FD_CHUNK);
409 if (rl.rlim_cur <= rlim_ofile_cur) { 410 if (rl.rlim_cur <= rlim_ofile_cur) {
410 syslog (LOG_ERR, "bump_nofile: cannot extend file limit, max = %d", 411 bb_error_msg ("bump_nofile: cannot extend file limit, max = %d",
411 (int) rl.rlim_cur); 412 (int) rl.rlim_cur);
412 return -1; 413 return -1;
413 } 414 }
414 415
415 if (setrlimit (RLIMIT_NOFILE, &rl) < 0) { 416 if (setrlimit (RLIMIT_NOFILE, &rl) < 0) {
416 syslog (LOG_ERR, "setrlimit: %m"); 417 bb_perror_msg ("setrlimit");
417 return -1; 418 return -1;
418 } 419 }
419 420
@@ -427,13 +428,13 @@ static void setup (servtab_t *sep)
427 int r; 428 int r;
428 429
429 if ((sep->se_fd = socket (sep->se_family, sep->se_socktype, 0)) < 0) { 430 if ((sep->se_fd = socket (sep->se_family, sep->se_socktype, 0)) < 0) {
430 syslog (LOG_ERR, "%s/%s: socket: %m", sep->se_service, sep->se_proto); 431 bb_perror_msg ("%s/%s: socket", sep->se_service, sep->se_proto);
431 return; 432 return;
432 } 433 }
433#define turnon(fd, opt) \ 434#define turnon(fd, opt) \
434setsockopt(fd, SOL_SOCKET, opt, (char *)&on, sizeof (on)) 435setsockopt(fd, SOL_SOCKET, opt, (char *)&on, sizeof (on))
435 if (turnon (sep->se_fd, SO_REUSEADDR) < 0) 436 if (turnon (sep->se_fd, SO_REUSEADDR) < 0)
436 syslog (LOG_ERR, "setsockopt (SO_REUSEADDR): %m"); 437 bb_perror_msg ("setsockopt (SO_REUSEADDR)");
437#undef turnon 438#undef turnon
438 439
439#ifdef CONFIG_FEATURE_INETD_RPC 440#ifdef CONFIG_FEATURE_INETD_RPC
@@ -467,7 +468,7 @@ setsockopt(fd, SOL_SOCKET, opt, (char *)&on, sizeof (on))
467#endif 468#endif
468 r = bind (sep->se_fd, &sep->se_ctrladdr, sep->se_ctrladdr_size); 469 r = bind (sep->se_fd, &sep->se_ctrladdr, sep->se_ctrladdr_size);
469 if (r < 0) { 470 if (r < 0) {
470 syslog (LOG_ERR, "%s/%s (%d): bind: %m", 471 bb_perror_msg ("%s/%s (%d): bind",
471 sep->se_service, sep->se_proto, sep->se_ctrladdr.sa_family); 472 sep->se_service, sep->se_proto, sep->se_ctrladdr.sa_family);
472 close (sep->se_fd); 473 close (sep->se_fd);
473 sep->se_fd = -1; 474 sep->se_fd = -1;
@@ -510,7 +511,7 @@ static char *skip (char **cpp) /* int report; */
510/* erp: */ 511/* erp: */
511 if (*cpp == NULL) { 512 if (*cpp == NULL) {
512 /* if (report) */ 513 /* if (report) */
513 /* syslog(LOG_ERR, "syntax error in inetd config file"); */ 514 /* bb_error_msg ("syntax error in inetd config file"); */
514 return (NULL); 515 return (NULL);
515 } 516 }
516 517
@@ -543,14 +544,7 @@ again:
543 544
544static servtab_t *new_servtab(void) 545static servtab_t *new_servtab(void)
545{ 546{
546 servtab_t *sep; 547 return xmalloc (sizeof (servtab_t));
547
548 sep = (servtab_t *) malloc (sizeof (servtab_t));
549 if (sep == NULL) {
550 syslog (LOG_ERR, bb_msg_memory_exhausted);
551 exit (1);
552 }
553 return sep;
554} 548}
555 549
556static servtab_t *dupconfig (servtab_t *sep) 550static servtab_t *dupconfig (servtab_t *sep)
@@ -560,26 +554,25 @@ static servtab_t *dupconfig (servtab_t *sep)
560 554
561 newtab = new_servtab(); 555 newtab = new_servtab();
562 memset (newtab, 0, sizeof (servtab_t)); 556 memset (newtab, 0, sizeof (servtab_t));
563 newtab->se_service = sep->se_service ? newstr (sep->se_service) : NULL; 557 newtab->se_service = xstrdup (sep->se_service);
564 newtab->se_socktype = sep->se_socktype; 558 newtab->se_socktype = sep->se_socktype;
565 newtab->se_family = sep->se_family; 559 newtab->se_family = sep->se_family;
566 newtab->se_proto = sep->se_proto ? newstr (sep->se_proto) : NULL; 560 newtab->se_proto = xstrdup (sep->se_proto);
567#ifdef CONFIG_FEATURE_INETD_RPC 561#ifdef CONFIG_FEATURE_INETD_RPC
568 newtab->se_rpcprog = sep->se_rpcprog; 562 newtab->se_rpcprog = sep->se_rpcprog;
569 newtab->se_rpcversl = sep->se_rpcversl; 563 newtab->se_rpcversl = sep->se_rpcversl;
570 newtab->se_rpcversh = sep->se_rpcversh; 564 newtab->se_rpcversh = sep->se_rpcversh;
571#endif 565#endif
572 newtab->se_wait = sep->se_wait; 566 newtab->se_wait = sep->se_wait;
573 newtab->se_user = sep->se_user ? newstr (sep->se_user) : NULL; 567 newtab->se_user = xstrdup (sep->se_user);
574 newtab->se_group = sep->se_group ? newstr (sep->se_group) : NULL; 568 newtab->se_group = xstrdup (sep->se_group);
575#ifdef INETD_FEATURE_ENABLED 569#ifdef INETD_FEATURE_ENABLED
576 newtab->se_bi = sep->se_bi; 570 newtab->se_bi = sep->se_bi;
577#endif 571#endif
578 newtab->se_server = sep->se_server ? newstr (sep->se_server) : 0; 572 newtab->se_server = xstrdup (sep->se_server);
579 573
580 for (argc = 0; argc <= MAXARGV; argc++) 574 for (argc = 0; argc <= MAXARGV; argc++)
581 newtab->se_argv[argc] = sep->se_argv[argc] ? 575 newtab->se_argv[argc] = xstrdup (sep->se_argv[argc]);
582 newstr (sep->se_argv[argc]) : NULL;
583 newtab->se_max = sep->se_max; 576 newtab->se_max = sep->se_max;
584 577
585 return (newtab); 578 return (newtab);
@@ -617,7 +610,7 @@ more:
617 hostdelim = strrchr (arg, ':'); 610 hostdelim = strrchr (arg, ':');
618 if (hostdelim) { 611 if (hostdelim) {
619 *hostdelim = '\0'; 612 *hostdelim = '\0';
620 sep->se_hostaddr = newstr (arg); 613 sep->se_hostaddr = xstrdup (arg);
621 arg = hostdelim + 1; 614 arg = hostdelim + 1;
622 /* 615 /*
623 * If the line is of the form `host:', then just change the 616 * If the line is of the form `host:', then just change the
@@ -632,9 +625,9 @@ more:
632 } 625 }
633 } 626 }
634 } else 627 } else
635 sep->se_hostaddr = newstr (defhost); 628 sep->se_hostaddr = xxstrdup (defhost);
636 629
637 sep->se_service = newstr (arg); 630 sep->se_service = xxstrdup (arg);
638 arg = skip (&cp); 631 arg = skip (&cp);
639 632
640 if (strcmp (arg, "stream") == 0) 633 if (strcmp (arg, "stream") == 0)
@@ -650,7 +643,7 @@ more:
650 else 643 else
651 sep->se_socktype = -1; 644 sep->se_socktype = -1;
652 645
653 sep->se_proto = newstr (skip (&cp)); 646 sep->se_proto = xxstrdup (skip (&cp));
654 647
655 if (strcmp (sep->se_proto, "unix") == 0) { 648 if (strcmp (sep->se_proto, "unix") == 0) {
656 sep->se_family = AF_UNIX; 649 sep->se_family = AF_UNIX;
@@ -660,7 +653,7 @@ more:
660#ifdef CONFIG_FEATURE_IPV6 653#ifdef CONFIG_FEATURE_IPV6
661 sep->se_family = AF_INET6; 654 sep->se_family = AF_INET6;
662#else 655#else
663 syslog (LOG_ERR, "%s: IPV6 not supported", sep->se_proto); 656 bb_error_msg ("%s: IPV6 not supported", sep->se_proto);
664#endif 657#endif
665 if (strncmp (sep->se_proto, "rpc/", 4) == 0) { 658 if (strncmp (sep->se_proto, "rpc/", 4) == 0) {
666#ifdef CONFIG_FEATURE_INETD_RPC 659#ifdef CONFIG_FEATURE_INETD_RPC
@@ -669,14 +662,14 @@ more:
669 662
670 p = strchr (sep->se_service, '/'); 663 p = strchr (sep->se_service, '/');
671 if (p == 0) { 664 if (p == 0) {
672 syslog (LOG_ERR, "%s: no rpc version", sep->se_service); 665 bb_error_msg ("%s: no rpc version", sep->se_service);
673 goto more; 666 goto more;
674 } 667 }
675 *p++ = '\0'; 668 *p++ = '\0';
676 l = strtol (p, &ccp, 0); 669 l = strtol (p, &ccp, 0);
677 if (ccp == p || l < 0 || l > INT_MAX) { 670 if (ccp == p || l < 0 || l > INT_MAX) {
678 badafterall: 671 badafterall:
679 syslog (LOG_ERR, "%s/%s: bad rpc version", sep->se_service, p); 672 bb_error_msg ("%s/%s: bad rpc version", sep->se_service, p);
680 goto more; 673 goto more;
681 } 674 }
682 sep->se_rpcversl = sep->se_rpcversh = l; 675 sep->se_rpcversl = sep->se_rpcversh = l;
@@ -689,7 +682,7 @@ more:
689 } else if (*ccp != '\0') 682 } else if (*ccp != '\0')
690 goto badafterall; 683 goto badafterall;
691#else 684#else
692 syslog (LOG_ERR, "%s: rpc services not supported", sep->se_service); 685 bb_error_msg ("%s: rpc services not supported", sep->se_service);
693#endif 686#endif
694 } 687 }
695 } 688 }
@@ -708,18 +701,18 @@ more:
708 sep->se_wait = strcmp (arg, "wait") == 0; 701 sep->se_wait = strcmp (arg, "wait") == 0;
709 /* if ((arg = skip(&cp, 1)) == NULL) */ 702 /* if ((arg = skip(&cp, 1)) == NULL) */
710 /* goto more; */ 703 /* goto more; */
711 sep->se_user = newstr (skip (&cp)); 704 sep->se_user = xxstrdup (skip (&cp));
712 arg = strchr (sep->se_user, '.'); 705 arg = strchr (sep->se_user, '.');
713 if (arg == NULL) 706 if (arg == NULL)
714 arg = strchr (sep->se_user, ':'); 707 arg = strchr (sep->se_user, ':');
715 if (arg) { 708 if (arg) {
716 *arg++ = '\0'; 709 *arg++ = '\0';
717 sep->se_group = newstr (arg); 710 sep->se_group = xstrdup (arg);
718 } 711 }
719 /* if ((arg = skip(&cp, 1)) == NULL) */ 712 /* if ((arg = skip(&cp, 1)) == NULL) */
720 /* goto more; */ 713 /* goto more; */
721 714
722 sep->se_server = newstr (skip (&cp)); 715 sep->se_server = xxstrdup (skip (&cp));
723 if (strcmp (sep->se_server, "internal") == 0) { 716 if (strcmp (sep->se_server, "internal") == 0) {
724#ifdef INETD_FEATURE_ENABLED 717#ifdef INETD_FEATURE_ENABLED
725 const struct builtin *bi; 718 const struct builtin *bi;
@@ -729,13 +722,13 @@ more:
729 strcmp (bi->bi_service, sep->se_service) == 0) 722 strcmp (bi->bi_service, sep->se_service) == 0)
730 break; 723 break;
731 if (bi->bi_service == 0) { 724 if (bi->bi_service == 0) {
732 syslog (LOG_ERR, "internal service %s unknown", sep->se_service); 725 bb_error_msg ("internal service %s unknown", sep->se_service);
733 goto more; 726 goto more;
734 } 727 }
735 sep->se_bi = bi; 728 sep->se_bi = bi;
736 sep->se_wait = bi->bi_wait; 729 sep->se_wait = bi->bi_wait;
737#else 730#else
738 syslog (LOG_ERR, "internal service %s unknown", sep->se_service); 731 bb_perror_msg ("internal service %s unknown", sep->se_service);
739 goto more; 732 goto more;
740#endif 733#endif
741 } 734 }
@@ -746,7 +739,7 @@ more:
746 argc = 0; 739 argc = 0;
747 for (arg = skip (&cp); cp; arg = skip (&cp)) { 740 for (arg = skip (&cp); cp; arg = skip (&cp)) {
748 if (argc < MAXARGV) 741 if (argc < MAXARGV)
749 sep->se_argv[argc++] = newstr (arg); 742 sep->se_argv[argc++] = xxstrdup (arg);
750 } 743 }
751 while (argc <= MAXARGV) 744 while (argc <= MAXARGV)
752 sep->se_argv[argc++] = NULL; 745 sep->se_argv[argc++] = NULL;
@@ -764,7 +757,7 @@ more:
764 * and make a dup for the new entry. 757 * and make a dup for the new entry.
765 */ 758 */
766 *hostdelim++ = '\0'; 759 *hostdelim++ = '\0';
767 nsep->se_hostaddr = newstr (hostdelim); 760 nsep->se_hostaddr = xstrdup (hostdelim);
768 761
769 nsep->se_next = sep->se_next; 762 nsep->se_next = sep->se_next;
770 sep->se_next = nsep; 763 sep->se_next = nsep;
@@ -781,12 +774,11 @@ more:
781 774
782 hp = gethostbyname (nsep->se_hostaddr); 775 hp = gethostbyname (nsep->se_hostaddr);
783 if (hp == 0) { 776 if (hp == 0) {
784 syslog (LOG_ERR, "%s: unknown host", nsep->se_hostaddr); 777 bb_error_msg ("%s: unknown host", nsep->se_hostaddr);
785 nsep->se_checked = 0; 778 nsep->se_checked = 0;
786 goto skip; 779 goto skip;
787 } else if (hp->h_addrtype != AF_INET) { 780 } else if (hp->h_addrtype != AF_INET) {
788 syslog (LOG_ERR, 781 bb_error_msg ("%s: address isn't an Internet "
789 "%s: address isn't an Internet "
790 "address", nsep->se_hostaddr); 782 "address", nsep->se_hostaddr);
791 nsep->se_checked = 0; 783 nsep->se_checked = 0;
792 goto skip; 784 goto skip;
@@ -797,7 +789,7 @@ more:
797 hp->h_addr_list[0], sizeof (struct in_addr)); 789 hp->h_addr_list[0], sizeof (struct in_addr));
798 while (hp->h_addr_list[i] != NULL) { 790 while (hp->h_addr_list[i] != NULL) {
799 psep = dupconfig (nsep); 791 psep = dupconfig (nsep);
800 psep->se_hostaddr = newstr (nsep->se_hostaddr); 792 psep->se_hostaddr = xxstrdup (nsep->se_hostaddr);
801 psep->se_checked = 1; 793 psep->se_checked = 1;
802 memmove (&psep->se_ctrladdr_in.sin_addr, 794 memmove (&psep->se_ctrladdr_in.sin_addr,
803 hp->h_addr_list[i], sizeof (struct in_addr)); 795 hp->h_addr_list[i], sizeof (struct in_addr));
@@ -913,7 +905,7 @@ static void config (int sig ATTRIBUTE_UNUSED)
913 char protoname[10]; 905 char protoname[10];
914 906
915 if (!setconfig ()) { 907 if (!setconfig ()) {
916 syslog (LOG_ERR, "%s: %m", CONFIG); 908 bb_perror_msg ("%s", CONFIG);
917 return; 909 return;
918 } 910 }
919 for (sep = servtab; sep; sep = sep->se_next) 911 for (sep = servtab; sep; sep = sep->se_next)
@@ -989,7 +981,7 @@ static void config (int sig ATTRIBUTE_UNUSED)
989 if (sep->se_rpcprog == 0) { 981 if (sep->se_rpcprog == 0) {
990 rp = getrpcbyname (sep->se_service); 982 rp = getrpcbyname (sep->se_service);
991 if (rp == 0) { 983 if (rp == 0) {
992 syslog (LOG_ERR, "%s: unknown rpc service", sep->se_service); 984 bb_error_msg ("%s: unknown rpc service", sep->se_service);
993 goto serv_unknown; 985 goto serv_unknown;
994 } 986 }
995 sep->se_rpcprog = rp->r_number; 987 sep->se_rpcprog = rp->r_number;
@@ -1009,8 +1001,8 @@ static void config (int sig ATTRIBUTE_UNUSED)
1009 protoname[strlen (protoname) - 1] = '\0'; 1001 protoname[strlen (protoname) - 1] = '\0';
1010 sp = getservbyname (sep->se_service, protoname); 1002 sp = getservbyname (sep->se_service, protoname);
1011 if (sp == 0) { 1003 if (sp == 0) {
1012 syslog (LOG_ERR, 1004 bb_error_msg ("%s/%s: unknown service",
1013 "%s/%s: unknown service", sep->se_service, sep->se_proto); 1005 sep->se_service, sep->se_proto);
1014 goto serv_unknown; 1006 goto serv_unknown;
1015 } 1007 }
1016 port = sp->s_port; 1008 port = sp->s_port;
@@ -1042,7 +1034,7 @@ static void config (int sig ATTRIBUTE_UNUSED)
1042 if (sep->se_rpcprog == 0) { 1034 if (sep->se_rpcprog == 0) {
1043 rp = getrpcbyname (sep->se_service); 1035 rp = getrpcbyname (sep->se_service);
1044 if (rp == 0) { 1036 if (rp == 0) {
1045 syslog (LOG_ERR, "%s: unknown rpc service", sep->se_service); 1037 bb_error_msg ("%s: unknown rpc service", sep->se_service);
1046 goto serv_unknown; 1038 goto serv_unknown;
1047 } 1039 }
1048 sep->se_rpcprog = rp->r_number; 1040 sep->se_rpcprog = rp->r_number;
@@ -1062,8 +1054,8 @@ static void config (int sig ATTRIBUTE_UNUSED)
1062 protoname[strlen (protoname) - 1] = '\0'; 1054 protoname[strlen (protoname) - 1] = '\0';
1063 sp = getservbyname (sep->se_service, protoname); 1055 sp = getservbyname (sep->se_service, protoname);
1064 if (sp == 0) { 1056 if (sp == 0) {
1065 syslog (LOG_ERR, 1057 bb_error_msg ("%s/%s: unknown service",
1066 "%s/%s: unknown service", sep->se_service, sep->se_proto); 1058 sep->se_service, sep->se_proto);
1067 goto serv_unknown; 1059 goto serv_unknown;
1068 } 1060 }
1069 port = sp->s_port; 1061 port = sp->s_port;
@@ -1137,12 +1129,11 @@ static void reapchild (int sig ATTRIBUTE_UNUSED)
1137 for (sep = servtab; sep; sep = sep->se_next) 1129 for (sep = servtab; sep; sep = sep->se_next)
1138 if (sep->se_wait == pid) { 1130 if (sep->se_wait == pid) {
1139 if (WIFEXITED (status) && WEXITSTATUS (status)) 1131 if (WIFEXITED (status) && WEXITSTATUS (status))
1140 syslog (LOG_WARNING, 1132 bb_error_msg("%s: exit status 0x%x",
1141 "%s: exit status 0x%x",
1142 sep->se_server, WEXITSTATUS (status)); 1133 sep->se_server, WEXITSTATUS (status));
1143 else if (WIFSIGNALED (status)) 1134 else if (WIFSIGNALED (status))
1144 syslog (LOG_WARNING, 1135 bb_error_msg("%s: exit signal 0x%x",
1145 "%s: exit signal 0x%x", sep->se_server, WTERMSIG (status)); 1136 sep->se_server, WTERMSIG (status));
1146 sep->se_wait = 1; 1137 sep->se_wait = 1;
1147 FD_SET (sep->se_fd, &allsock); 1138 FD_SET (sep->se_fd, &allsock);
1148 nsock++; 1139 nsock++;
@@ -1271,7 +1262,7 @@ inetd_main (int argc, char *argv[])
1271 toomany = strtoul (stoomany, &e, 0); 1262 toomany = strtoul (stoomany, &e, 0);
1272 if (!(toomany >= 0 && *e == '\0')) { 1263 if (!(toomany >= 0 && *e == '\0')) {
1273 toomany = TOOMANY; 1264 toomany = TOOMANY;
1274 syslog (LOG_ERR, "-R %s: bad value for service invocation rate", stoomany); 1265 bb_perror_msg ("-R %s: bad value for service invocation rate", stoomany);
1275 } 1266 }
1276 } 1267 }
1277 argc -= optind; 1268 argc -= optind;
@@ -1295,6 +1286,7 @@ inetd_main (int argc, char *argv[])
1295 } else { 1286 } else {
1296 setsid (); 1287 setsid ();
1297 } 1288 }
1289 logmode = LOGMODE_SYSLOG;
1298 1290
1299 if (uid == 0) { 1291 if (uid == 0) {
1300 gid_t gid = getgid (); 1292 gid_t gid = getgid ();
@@ -1313,7 +1305,7 @@ inetd_main (int argc, char *argv[])
1313 } 1305 }
1314 1306
1315 if (getrlimit (RLIMIT_NOFILE, &rlim_ofile) < 0) { 1307 if (getrlimit (RLIMIT_NOFILE, &rlim_ofile) < 0) {
1316 syslog (LOG_ERR, "getrlimit: %m"); 1308 bb_perror_msg ("getrlimit");
1317 } else { 1309 } else {
1318 rlim_ofile_cur = rlim_ofile.rlim_cur; 1310 rlim_ofile_cur = rlim_ofile.rlim_cur;
1319 if (rlim_ofile_cur == RLIM_INFINITY) /* ! */ 1311 if (rlim_ofile_cur == RLIM_INFINITY) /* ! */
@@ -1365,7 +1357,7 @@ inetd_main (int argc, char *argv[])
1365 readable = allsock; 1357 readable = allsock;
1366 if ((n = select (maxsock + 1, &readable, NULL, NULL, NULL)) <= 0) { 1358 if ((n = select (maxsock + 1, &readable, NULL, NULL, NULL)) <= 0) {
1367 if (n < 0 && errno != EINTR) { 1359 if (n < 0 && errno != EINTR) {
1368 syslog (LOG_WARNING, "select: %m"); 1360 bb_perror_msg("select");
1369 sleep (1); 1361 sleep (1);
1370 } 1362 }
1371 continue; 1363 continue;
@@ -1378,7 +1370,7 @@ inetd_main (int argc, char *argv[])
1378 if (ctrl < 0) { 1370 if (ctrl < 0) {
1379 if (errno == EINTR) 1371 if (errno == EINTR)
1380 continue; 1372 continue;
1381 syslog (LOG_WARNING, "accept (for %s): %m", sep->se_service); 1373 bb_perror_msg("accept (for %s)", sep->se_service);
1382 continue; 1374 continue;
1383 } 1375 }
1384 if (sep->se_family == AF_INET && sep->se_socktype == SOCK_STREAM) { 1376 if (sep->se_family == AF_INET && sep->se_socktype == SOCK_STREAM) {
@@ -1386,7 +1378,7 @@ inetd_main (int argc, char *argv[])
1386 socklen_t plen = sizeof (peer); 1378 socklen_t plen = sizeof (peer);
1387 1379
1388 if (getpeername (ctrl, (struct sockaddr *) &peer, &plen) < 0) { 1380 if (getpeername (ctrl, (struct sockaddr *) &peer, &plen) < 0) {
1389 syslog (LOG_WARNING, "could not getpeername"); 1381 bb_error_msg("could not getpeername");
1390 close (ctrl); 1382 close (ctrl);
1391 continue; 1383 continue;
1392 } 1384 }
@@ -1426,8 +1418,7 @@ inetd_main (int argc, char *argv[])
1426 --sep->se_count; 1418 --sep->se_count;
1427 continue; 1419 continue;
1428 } 1420 }
1429 syslog (LOG_ERR, 1421 bb_error_msg ("%s/%s server failing (looping), service terminated",
1430 "%s/%s server failing (looping), service terminated",
1431 sep->se_service, sep->se_proto); 1422 sep->se_service, sep->se_proto);
1432 if (!sep->se_wait && sep->se_socktype == SOCK_STREAM) 1423 if (!sep->se_wait && sep->se_socktype == SOCK_STREAM)
1433 close (ctrl); 1424 close (ctrl);
@@ -1447,7 +1438,7 @@ inetd_main (int argc, char *argv[])
1447 pid = fork (); 1438 pid = fork ();
1448 } 1439 }
1449 if (pid < 0) { 1440 if (pid < 0) {
1450 syslog (LOG_ERR, "fork: %m"); 1441 bb_perror_msg ("fork");
1451 if (!sep->se_wait && sep->se_socktype == SOCK_STREAM) 1442 if (!sep->se_wait && sep->se_socktype == SOCK_STREAM)
1452 close (ctrl); 1443 close (ctrl);
1453 sigprocmask(SIG_UNBLOCK, &omask, NULL); 1444 sigprocmask(SIG_UNBLOCK, &omask, NULL);
@@ -1468,15 +1459,15 @@ inetd_main (int argc, char *argv[])
1468#endif 1459#endif
1469 { 1460 {
1470 if ((pwd = getpwnam (sep->se_user)) == NULL) { 1461 if ((pwd = getpwnam (sep->se_user)) == NULL) {
1471 syslog (LOG_ERR, "getpwnam: %s: No such user", sep->se_user); 1462 bb_error_msg ("getpwnam: %s: no such user", sep->se_user);
1472 if (sep->se_socktype != SOCK_STREAM) 1463 if (sep->se_socktype != SOCK_STREAM)
1473 recv (0, buf, sizeof (buf), 0); 1464 recv (0, buf, sizeof (buf), 0);
1474 _exit (1); 1465 _exit (1);
1475 } 1466 }
1476 if (setsid () < 0) 1467 if (setsid () < 0)
1477 syslog (LOG_ERR, "%s: setsid: %m", sep->se_service); 1468 bb_perror_msg ("%s: setsid", sep->se_service);
1478 if (sep->se_group && (grp = getgrnam (sep->se_group)) == NULL) { 1469 if (sep->se_group && (grp = getgrnam (sep->se_group)) == NULL) {
1479 syslog (LOG_ERR, "getgrnam: %s: No such group", sep->se_group); 1470 bb_error_msg ("getgrnam: %s: no such group", sep->se_group);
1480 if (sep->se_socktype != SOCK_STREAM) 1471 if (sep->se_socktype != SOCK_STREAM)
1481 recv (0, buf, sizeof (buf), 0); 1472 recv (0, buf, sizeof (buf), 0);
1482 _exit (1); 1473 _exit (1);
@@ -1502,7 +1493,7 @@ inetd_main (int argc, char *argv[])
1502 dup2 (0, 2); 1493 dup2 (0, 2);
1503 if (rlim_ofile.rlim_cur != rlim_ofile_cur) 1494 if (rlim_ofile.rlim_cur != rlim_ofile_cur)
1504 if (setrlimit (RLIMIT_NOFILE, &rlim_ofile) < 0) 1495 if (setrlimit (RLIMIT_NOFILE, &rlim_ofile) < 0)
1505 syslog (LOG_ERR, "setrlimit: %m"); 1496 bb_perror_msg ("setrlimit");
1506 closelog (); 1497 closelog ();
1507 for (tmpint = rlim_ofile_cur - 1; --tmpint > 2;) 1498 for (tmpint = rlim_ofile_cur - 1; --tmpint > 2;)
1508 (void) close (tmpint); 1499 (void) close (tmpint);
@@ -1510,7 +1501,7 @@ inetd_main (int argc, char *argv[])
1510 execv (sep->se_server, sep->se_argv); 1501 execv (sep->se_server, sep->se_argv);
1511 if (sep->se_socktype != SOCK_STREAM) 1502 if (sep->se_socktype != SOCK_STREAM)
1512 recv (0, buf, sizeof (buf), 0); 1503 recv (0, buf, sizeof (buf), 0);
1513 syslog (LOG_ERR, "execv %s: %m", sep->se_server); 1504 bb_perror_msg ("execv %s", sep->se_server);
1514 _exit (1); 1505 _exit (1);
1515 } 1506 }
1516 } 1507 }
diff --git a/networking/ipcalc.c b/networking/ipcalc.c
index 9838fcfda..aafb7869b 100644
--- a/networking/ipcalc.c
+++ b/networking/ipcalc.c
@@ -119,7 +119,7 @@ int ipcalc_main(int argc, char **argv)
119 unsigned int msk; 119 unsigned int msk;
120 120
121 if (safe_strtoul(prefixstr, &netprefix) || netprefix > 32) { 121 if (safe_strtoul(prefixstr, &netprefix) || netprefix > 32) {
122 IPCALC_MSG(bb_error_msg_and_die("bad IP prefix: %s\n", prefixstr), 122 IPCALC_MSG(bb_error_msg_and_die("bad IP prefix: %s", prefixstr),
123 exit(EXIT_FAILURE)); 123 exit(EXIT_FAILURE));
124 } 124 }
125 netmask = 0; 125 netmask = 0;
@@ -149,7 +149,7 @@ int ipcalc_main(int argc, char **argv)
149 149
150 if (argc == 2) { 150 if (argc == 2) {
151 if (ENABLE_FEATURE_IPCALC_FANCY && have_netmask) { 151 if (ENABLE_FEATURE_IPCALC_FANCY && have_netmask) {
152 IPCALC_MSG(bb_error_msg_and_die("Use prefix or netmask, not both.\n"), 152 IPCALC_MSG(bb_error_msg_and_die("Use prefix or netmask, not both"),
153 exit(EXIT_FAILURE)); 153 exit(EXIT_FAILURE));
154 } 154 }
155 155
diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c
index 511e89107..c4bbd98b1 100644
--- a/networking/libiproute/iproute.c
+++ b/networking/libiproute/iproute.c
@@ -608,7 +608,7 @@ static int iproute_list_or_flush(int argc, char **argv, int flush)
608 } 608 }
609 filter.flushed = 0; 609 filter.flushed = 0;
610 if (rtnl_dump_filter(&rth, print_route, stdout, NULL, NULL) < 0) { 610 if (rtnl_dump_filter(&rth, print_route, stdout, NULL, NULL) < 0) {
611 bb_error_msg("Flush terminated\n"); 611 bb_error_msg("Flush terminated");
612 return -1; 612 return -1;
613 } 613 }
614 if (filter.flushed == 0) { 614 if (filter.flushed == 0) {
diff --git a/networking/nameif.c b/networking/nameif.c
index 501e244b1..3fa257263 100644
--- a/networking/nameif.c
+++ b/networking/nameif.c
@@ -41,29 +41,6 @@ typedef struct mactable_s {
41 struct ether_addr *mac; 41 struct ether_addr *mac;
42} mactable_t; 42} mactable_t;
43 43
44static unsigned long flags;
45
46static void serror(const char *s, ...) ATTRIBUTE_NORETURN;
47
48static void serror(const char *s, ...)
49{
50 va_list ap;
51
52 va_start(ap, s);
53
54 if (flags & 1) {
55 openlog(bb_applet_name, 0, LOG_LOCAL0);
56 vsyslog(LOG_ERR, s, ap);
57 closelog();
58 } else {
59 bb_verror_msg(s, ap);
60 putc('\n', stderr);
61 }
62 va_end(ap);
63
64 exit(EXIT_FAILURE);
65}
66
67/* Check ascii str_macaddr, convert and copy to *mac */ 44/* Check ascii str_macaddr, convert and copy to *mac */
68static struct ether_addr *cc_macaddr(const char *str_macaddr) 45static struct ether_addr *cc_macaddr(const char *str_macaddr)
69{ 46{
@@ -71,7 +48,7 @@ static struct ether_addr *cc_macaddr(const char *str_macaddr)
71 48
72 lmac = ether_aton(str_macaddr); 49 lmac = ether_aton(str_macaddr);
73 if (lmac == NULL) 50 if (lmac == NULL)
74 serror("cannot parse MAC %s", str_macaddr); 51 bb_error_msg_and_die("cannot parse MAC %s", str_macaddr);
75 mac = xmalloc(ETH_ALEN); 52 mac = xmalloc(ETH_ALEN);
76 memcpy(mac, lmac, ETH_ALEN); 53 memcpy(mac, lmac, ETH_ALEN);
77 54
@@ -88,7 +65,10 @@ int nameif_main(int argc, char **argv)
88 int if_index = 1; 65 int if_index = 1;
89 mactable_t *ch; 66 mactable_t *ch;
90 67
91 flags = bb_getopt_ulflags(argc, argv, "sc:", &fname); 68 if (1 & bb_getopt_ulflags(argc, argv, "sc:", &fname)) {
69 openlog(bb_applet_name, 0, LOG_LOCAL0);
70 logmode = LOGMODE_SYSLOG;
71 }
92 72
93 if ((argc - optind) & 1) 73 if ((argc - optind) & 1)
94 bb_show_usage(); 74 bb_show_usage();
@@ -97,9 +77,9 @@ int nameif_main(int argc, char **argv)
97 char **a = argv + optind; 77 char **a = argv + optind;
98 78
99 while (*a) { 79 while (*a) {
100
101 if (strlen(*a) > IF_NAMESIZE) 80 if (strlen(*a) > IF_NAMESIZE)
102 serror("interface name `%s' too long", *a); 81 bb_error_msg_and_die("interface name `%s' "
82 "too long", *a);
103 ch = xzalloc(sizeof(mactable_t)); 83 ch = xzalloc(sizeof(mactable_t));
104 ch->ifname = xstrdup(*a++); 84 ch->ifname = xstrdup(*a++);
105 ch->mac = cc_macaddr(*a++); 85 ch->mac = cc_macaddr(*a++);
@@ -124,7 +104,8 @@ int nameif_main(int argc, char **argv)
124 ch = xzalloc(sizeof(mactable_t)); 104 ch = xzalloc(sizeof(mactable_t));
125 ch->ifname = xstrndup(line_ptr, name_length); 105 ch->ifname = xstrndup(line_ptr, name_length);
126 if (name_length > IF_NAMESIZE) 106 if (name_length > IF_NAMESIZE)
127 serror("interface name `%s' too long", ch->ifname); 107 bb_error_msg_and_die("interface name `%s' "
108 "too long", ch->ifname);
128 line_ptr += name_length; 109 line_ptr += name_length;
129 line_ptr += strspn(line_ptr, " \t"); 110 line_ptr += strspn(line_ptr, " \t");
130 name_length = strspn(line_ptr, "0123456789ABCDEFabcdef:"); 111 name_length = strspn(line_ptr, "0123456789ABCDEFabcdef:");
@@ -139,8 +120,7 @@ int nameif_main(int argc, char **argv)
139 fclose(ifh); 120 fclose(ifh);
140 } 121 }
141 122
142 if ((ctl_sk = socket(PF_INET, SOCK_DGRAM, 0)) == -1) 123 ctl_sk = xsocket(PF_INET, SOCK_DGRAM, 0);
143 serror("socket: %m");
144 124
145 while (clist) { 125 while (clist) {
146 struct ifreq ifr; 126 struct ifreq ifr;
@@ -168,7 +148,7 @@ int nameif_main(int argc, char **argv)
168 148
169 strcpy(ifr.ifr_newname, ch->ifname); 149 strcpy(ifr.ifr_newname, ch->ifname);
170 if (ioctl(ctl_sk, SIOCSIFNAME, &ifr) < 0) 150 if (ioctl(ctl_sk, SIOCSIFNAME, &ifr) < 0)
171 serror("cannot change ifname %s to %s: %m", 151 bb_perror_msg_and_die("cannot change ifname %s to %s",
172 ifr.ifr_name, ch->ifname); 152 ifr.ifr_name, ch->ifname);
173 153
174 /* Remove list entry of renamed interface */ 154 /* Remove list entry of renamed interface */
diff --git a/networking/telnetd.c b/networking/telnetd.c
index 87f44ce51..890e58466 100644
--- a/networking/telnetd.c
+++ b/networking/telnetd.c
@@ -263,7 +263,7 @@ make_new_session(int sockfd)
263 pty = getpty(tty_name); 263 pty = getpty(tty_name);
264 264
265 if (pty < 0) { 265 if (pty < 0) {
266 syslog(LOG_ERR, "All terminals in use!"); 266 bb_error_msg("all terminals in use");
267 return 0; 267 return 0;
268 } 268 }
269 269
@@ -285,7 +285,7 @@ make_new_session(int sockfd)
285 send_iac(ts, WILL, TELOPT_SGA); 285 send_iac(ts, WILL, TELOPT_SGA);
286 286
287 if ((pid = fork()) < 0) { 287 if ((pid = fork()) < 0) {
288 syslog(LOG_ERR, "Could not fork"); 288 bb_perror_msg("fork");
289 } 289 }
290 if (pid == 0) { 290 if (pid == 0) {
291 /* In child, open the child's side of the tty. */ 291 /* In child, open the child's side of the tty. */
@@ -296,10 +296,7 @@ make_new_session(int sockfd)
296 /* make new process group */ 296 /* make new process group */
297 setsid(); 297 setsid();
298 298
299 if (open(tty_name, O_RDWR /*| O_NOCTTY*/) < 0) { 299 xopen(tty_name, O_RDWR /*| O_NOCTTY*/);
300 syslog(LOG_ERR, "Could not open tty");
301 exit(1);
302 }
303 dup(0); 300 dup(0);
304 dup(0); 301 dup(0);
305 302
@@ -323,8 +320,7 @@ make_new_session(int sockfd)
323 execv(loginpath, (char *const *)argv_init); 320 execv(loginpath, (char *const *)argv_init);
324 321
325 /* NOT REACHED */ 322 /* NOT REACHED */
326 syslog(LOG_ERR, "execv error"); 323 bb_perror_msg_and_die("execv");
327 exit(1);
328 } 324 }
329 325
330 ts->shell_pid = pid; 326 ts->shell_pid = pid;
@@ -390,6 +386,14 @@ telnetd_main(int argc, char **argv)
390 loginpath = DEFAULT_SHELL; 386 loginpath = DEFAULT_SHELL;
391#endif 387#endif
392 388
389 /* We use inetd-style operation unconditionally
390 * (no --foreground option), user most likely will
391 * look into syslog for all errors, even early ones.
392 * Direct all output to syslog at once.
393 */
394 openlog(bb_applet_name, 0, LOG_USER);
395 logmode = LOGMODE_SYSLOG;
396
393 for (;;) { 397 for (;;) {
394 c = getopt( argc, argv, options); 398 c = getopt( argc, argv, options);
395 if (c == EOF) break; 399 if (c == EOF) break;
@@ -415,13 +419,11 @@ telnetd_main(int argc, char **argv)
415 } 419 }
416 420
417 if (access(loginpath, X_OK) < 0) { 421 if (access(loginpath, X_OK) < 0) {
418 bb_error_msg_and_die ("'%s' unavailable.", loginpath); 422 bb_error_msg_and_die("'%s' unavailable", loginpath);
419 } 423 }
420 424
421 argv_init[0] = loginpath; 425 argv_init[0] = loginpath;
422 426
423 openlog(bb_applet_name, 0, LOG_USER);
424
425#ifdef CONFIG_FEATURE_TELNETD_INETD 427#ifdef CONFIG_FEATURE_TELNETD_INETD
426 maxfd = 1; 428 maxfd = 1;
427 sessions = make_new_session(); 429 sessions = make_new_session();
diff --git a/networking/traceroute.c b/networking/traceroute.c
index b6a885544..3e142d01a 100644
--- a/networking/traceroute.c
+++ b/networking/traceroute.c
@@ -515,16 +515,16 @@ str2val(const char *str, const char *what, int mi, int ma)
515 } else 515 } else
516 val = (int)strtol(str, &ep, 10); 516 val = (int)strtol(str, &ep, 10);
517 if (*ep != '\0') { 517 if (*ep != '\0') {
518 bb_error_msg_and_die("\"%s\" bad value for %s \n", str, what); 518 bb_error_msg_and_die("\"%s\" bad value for %s", str, what);
519 } 519 }
520 if (val < mi && mi >= 0) { 520 if (val < mi && mi >= 0) {
521 if (mi == 0) 521 if (mi == 0)
522 bb_error_msg_and_die("%s must be >= %d\n", what, mi); 522 bb_error_msg_and_die("%s must be >= %d", what, mi);
523 else 523 else
524 bb_error_msg_and_die("%s must be > %d\n", what, mi - 1); 524 bb_error_msg_and_die("%s must be > %d", what, mi - 1);
525 } 525 }
526 if (val > ma && ma >= 0) 526 if (val > ma && ma >= 0)
527 bb_error_msg_and_die("%s must be <= %d\n", what, ma); 527 bb_error_msg_and_die("%s must be <= %d", what, ma);
528 return val; 528 return val;
529} 529}
530 530
diff --git a/networking/udhcp/arpping.c b/networking/udhcp/arpping.c
index 6e254f604..587339f9b 100644
--- a/networking/udhcp/arpping.c
+++ b/networking/udhcp/arpping.c
@@ -43,13 +43,13 @@ int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface)
43 time_t prevTime; 43 time_t prevTime;
44 44
45 45
46 if ((s = socket (PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP))) == -1) { 46 if ((s = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP))) == -1) {
47 LOG(LOG_ERR, bb_msg_can_not_create_raw_socket); 47 bb_perror_msg(bb_msg_can_not_create_raw_socket);
48 return -1; 48 return -1;
49 } 49 }
50 50
51 if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) == -1) { 51 if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) == -1) {
52 LOG(LOG_ERR, "Could not setsocketopt on raw socket"); 52 bb_perror_msg("Could not setsocketopt on raw socket");
53 close(s); 53 close(s);
54 return -1; 54 return -1;
55 } 55 }
@@ -81,14 +81,14 @@ int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface)
81 FD_SET(s, &fdset); 81 FD_SET(s, &fdset);
82 tm.tv_sec = timeout; 82 tm.tv_sec = timeout;
83 if (select(s + 1, &fdset, (fd_set *) NULL, (fd_set *) NULL, &tm) < 0) { 83 if (select(s + 1, &fdset, (fd_set *) NULL, (fd_set *) NULL, &tm) < 0) {
84 DEBUG(LOG_ERR, "Error on ARPING request: %m"); 84 bb_perror_msg("Error on ARPING request");
85 if (errno != EINTR) rv = 0; 85 if (errno != EINTR) rv = 0;
86 } else if (FD_ISSET(s, &fdset)) { 86 } else if (FD_ISSET(s, &fdset)) {
87 if (recv(s, &arp, sizeof(arp), 0) < 0 ) rv = 0; 87 if (recv(s, &arp, sizeof(arp), 0) < 0 ) rv = 0;
88 if (arp.operation == htons(ARPOP_REPLY) && 88 if (arp.operation == htons(ARPOP_REPLY) &&
89 memcmp(arp.tHaddr, mac, 6) == 0 && 89 memcmp(arp.tHaddr, mac, 6) == 0 &&
90 *((uint32_t *) arp.sInaddr) == yiaddr) { 90 *((uint32_t *) arp.sInaddr) == yiaddr) {
91 DEBUG(LOG_INFO, "Valid arp reply receved for this address"); 91 DEBUG("Valid arp reply received for this address");
92 rv = 0; 92 rv = 0;
93 break; 93 break;
94 } 94 }
@@ -97,6 +97,6 @@ int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface)
97 prevTime = uptime(); 97 prevTime = uptime();
98 } 98 }
99 close(s); 99 close(s);
100 DEBUG(LOG_INFO, "%salid arp replies for this address", rv ? "No v" : "V"); 100 DEBUG("%salid arp replies for this address", rv ? "No v" : "V");
101 return rv; 101 return rv;
102} 102}
diff --git a/networking/udhcp/clientpacket.c b/networking/udhcp/clientpacket.c
index 82975700c..f7e7d442c 100644
--- a/networking/udhcp/clientpacket.c
+++ b/networking/udhcp/clientpacket.c
@@ -44,7 +44,8 @@ unsigned long random_xid(void)
44 44
45 fd = open("/dev/urandom", 0); 45 fd = open("/dev/urandom", 0);
46 if (fd < 0 || read(fd, &seed, sizeof(seed)) < 0) { 46 if (fd < 0 || read(fd, &seed, sizeof(seed)) < 0) {
47 LOG(LOG_WARNING, "Could not load seed from /dev/urandom: %m"); 47 bb_info_msg("Could not load seed "
48 "from /dev/urandom: %s", strerror(errno));
48 seed = time(0); 49 seed = time(0);
49 } 50 }
50 if (fd >= 0) close(fd); 51 if (fd >= 0) close(fd);
@@ -97,7 +98,7 @@ int send_discover(unsigned long xid, unsigned long requested)
97 add_simple_option(packet.options, DHCP_REQUESTED_IP, requested); 98 add_simple_option(packet.options, DHCP_REQUESTED_IP, requested);
98 99
99 add_requests(&packet); 100 add_requests(&packet);
100 LOG(LOG_DEBUG, "Sending discover..."); 101 bb_info_msg("Sending discover...");
101 return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, 102 return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
102 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); 103 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
103} 104}
@@ -117,7 +118,7 @@ int send_selecting(unsigned long xid, unsigned long server, unsigned long reques
117 118
118 add_requests(&packet); 119 add_requests(&packet);
119 addr.s_addr = requested; 120 addr.s_addr = requested;
120 LOG(LOG_DEBUG, "Sending select for %s...", inet_ntoa(addr)); 121 bb_info_msg("Sending select for %s...", inet_ntoa(addr));
121 return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, 122 return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
122 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); 123 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
123} 124}
@@ -134,7 +135,7 @@ int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr)
134 packet.ciaddr = ciaddr; 135 packet.ciaddr = ciaddr;
135 136
136 add_requests(&packet); 137 add_requests(&packet);
137 LOG(LOG_DEBUG, "Sending renew..."); 138 bb_info_msg("Sending renew...");
138 if (server) 139 if (server)
139 ret = udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); 140 ret = udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT);
140 else ret = udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, 141 else ret = udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
@@ -155,7 +156,7 @@ int send_release(unsigned long server, unsigned long ciaddr)
155 add_simple_option(packet.options, DHCP_REQUESTED_IP, ciaddr); 156 add_simple_option(packet.options, DHCP_REQUESTED_IP, ciaddr);
156 add_simple_option(packet.options, DHCP_SERVER_ID, server); 157 add_simple_option(packet.options, DHCP_SERVER_ID, server);
157 158
158 LOG(LOG_DEBUG, "Sending release..."); 159 bb_info_msg("Sending release...");
159 return udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); 160 return udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT);
160} 161}
161 162
@@ -171,18 +172,18 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
171 memset(&packet, 0, sizeof(struct udp_dhcp_packet)); 172 memset(&packet, 0, sizeof(struct udp_dhcp_packet));
172 bytes = read(fd, &packet, sizeof(struct udp_dhcp_packet)); 173 bytes = read(fd, &packet, sizeof(struct udp_dhcp_packet));
173 if (bytes < 0) { 174 if (bytes < 0) {
174 DEBUG(LOG_INFO, "couldn't read on raw listening socket -- ignoring"); 175 DEBUG("Couldn't read on raw listening socket - ignoring");
175 usleep(500000); /* possible down interface, looping condition */ 176 usleep(500000); /* possible down interface, looping condition */
176 return -1; 177 return -1;
177 } 178 }
178 179
179 if (bytes < (int) (sizeof(struct iphdr) + sizeof(struct udphdr))) { 180 if (bytes < (int) (sizeof(struct iphdr) + sizeof(struct udphdr))) {
180 DEBUG(LOG_INFO, "message too short, ignoring"); 181 DEBUG("Message too short, ignoring");
181 return -2; 182 return -2;
182 } 183 }
183 184
184 if (bytes < ntohs(packet.ip.tot_len)) { 185 if (bytes < ntohs(packet.ip.tot_len)) {
185 DEBUG(LOG_INFO, "Truncated packet"); 186 DEBUG("Truncated packet");
186 return -2; 187 return -2;
187 } 188 }
188 189
@@ -194,7 +195,7 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
194 packet.ip.ihl != sizeof(packet.ip) >> 2 || packet.udp.dest != htons(CLIENT_PORT) || 195 packet.ip.ihl != sizeof(packet.ip) >> 2 || packet.udp.dest != htons(CLIENT_PORT) ||
195 bytes > (int) sizeof(struct udp_dhcp_packet) || 196 bytes > (int) sizeof(struct udp_dhcp_packet) ||
196 ntohs(packet.udp.len) != (uint16_t) (bytes - sizeof(packet.ip))) { 197 ntohs(packet.udp.len) != (uint16_t) (bytes - sizeof(packet.ip))) {
197 DEBUG(LOG_INFO, "unrelated/bogus packet"); 198 DEBUG("Unrelated/bogus packet");
198 return -2; 199 return -2;
199 } 200 }
200 201
@@ -202,7 +203,7 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
202 check = packet.ip.check; 203 check = packet.ip.check;
203 packet.ip.check = 0; 204 packet.ip.check = 0;
204 if (check != udhcp_checksum(&(packet.ip), sizeof(packet.ip))) { 205 if (check != udhcp_checksum(&(packet.ip), sizeof(packet.ip))) {
205 DEBUG(LOG_INFO, "bad IP header checksum, ignoring"); 206 DEBUG("bad IP header checksum, ignoring");
206 return -1; 207 return -1;
207 } 208 }
208 209
@@ -218,17 +219,17 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
218 packet.ip.daddr = dest; 219 packet.ip.daddr = dest;
219 packet.ip.tot_len = packet.udp.len; /* cheat on the psuedo-header */ 220 packet.ip.tot_len = packet.udp.len; /* cheat on the psuedo-header */
220 if (check && check != udhcp_checksum(&packet, bytes)) { 221 if (check && check != udhcp_checksum(&packet, bytes)) {
221 DEBUG(LOG_ERR, "packet with bad UDP checksum received, ignoring"); 222 bb_error_msg("Packet with bad UDP checksum received, ignoring");
222 return -2; 223 return -2;
223 } 224 }
224 225
225 memcpy(payload, &(packet.data), bytes - (sizeof(packet.ip) + sizeof(packet.udp))); 226 memcpy(payload, &(packet.data), bytes - (sizeof(packet.ip) + sizeof(packet.udp)));
226 227
227 if (ntohl(payload->cookie) != DHCP_MAGIC) { 228 if (ntohl(payload->cookie) != DHCP_MAGIC) {
228 LOG(LOG_ERR, "received bogus message (bad magic) -- ignoring"); 229 bb_error_msg("Received bogus message (bad magic) - ignoring");
229 return -2; 230 return -2;
230 } 231 }
231 DEBUG(LOG_INFO, "oooooh!!! got some!"); 232 DEBUG("oooooh!!! got some!");
232 return bytes - (sizeof(packet.ip) + sizeof(packet.udp)); 233 return bytes - (sizeof(packet.ip) + sizeof(packet.udp));
233 234
234} 235}
diff --git a/networking/udhcp/clientsocket.c b/networking/udhcp/clientsocket.c
index a1c4eadab..982aca1bb 100644
--- a/networking/udhcp/clientsocket.c
+++ b/networking/udhcp/clientsocket.c
@@ -44,9 +44,9 @@ int raw_socket(int ifindex)
44 int fd; 44 int fd;
45 struct sockaddr_ll sock; 45 struct sockaddr_ll sock;
46 46
47 DEBUG(LOG_INFO, "Opening raw socket on ifindex %d", ifindex); 47 DEBUG("Opening raw socket on ifindex %d", ifindex);
48 if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) { 48 if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) {
49 DEBUG(LOG_ERR, "socket call failed: %m"); 49 bb_perror_msg("socket");
50 return -1; 50 return -1;
51 } 51 }
52 52
@@ -54,7 +54,7 @@ int raw_socket(int ifindex)
54 sock.sll_protocol = htons(ETH_P_IP); 54 sock.sll_protocol = htons(ETH_P_IP);
55 sock.sll_ifindex = ifindex; 55 sock.sll_ifindex = ifindex;
56 if (bind(fd, (struct sockaddr *) &sock, sizeof(sock)) < 0) { 56 if (bind(fd, (struct sockaddr *) &sock, sizeof(sock)) < 0) {
57 DEBUG(LOG_ERR, "bind call failed: %m"); 57 bb_perror_msg("bind:");
58 close(fd); 58 close(fd);
59 return -1; 59 return -1;
60 } 60 }
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c
index c2025e588..1ae65f750 100644
--- a/networking/udhcp/common.c
+++ b/networking/udhcp/common.c
@@ -19,6 +19,7 @@
19#include <paths.h> 19#include <paths.h>
20#include <sys/socket.h> 20#include <sys/socket.h>
21#include <stdarg.h> 21#include <stdarg.h>
22#include <syslog.h>
22 23
23#include "common.h" 24#include "common.h"
24#include "pidfile.h" 25#include "pidfile.h"
@@ -33,7 +34,6 @@ long uptime(void)
33 return info.uptime; 34 return info.uptime;
34} 35}
35 36
36
37/* 37/*
38 * This function makes sure our first socket calls 38 * This function makes sure our first socket calls
39 * aren't going to fd 1 (printf badness...) and are 39 * aren't going to fd 1 (printf badness...) and are
@@ -41,77 +41,32 @@ long uptime(void)
41 */ 41 */
42static inline void sanitize_fds(void) 42static inline void sanitize_fds(void)
43{ 43{
44 int zero; 44 int fd = open(bb_dev_null, O_RDWR, 0);
45 if ((zero = open(bb_dev_null, O_RDWR, 0)) < 0) 45 if (fd < 0)
46 return; 46 return;
47 while (zero < 3) 47 while (fd < 3)
48 zero = dup(zero); 48 fd = dup(fd);
49 close(zero); 49 close(fd);
50} 50}
51 51
52 52
53void udhcp_background(const char *pidfile) 53void udhcp_background(const char *pidfile)
54{ 54{
55#ifdef __uClinux__ 55#ifdef __uClinux__
56 LOG(LOG_ERR, "Cannot background in uclinux (yet)"); 56 bb_error_msg("Cannot background in uclinux (yet)");
57#else /* __uClinux__ */ 57#else /* __uClinux__ */
58 int pid_fd; 58 int pid_fd;
59 59
60 /* hold lock during fork. */ 60 /* hold lock during fork. */
61 pid_fd = pidfile_acquire(pidfile); 61 pid_fd = pidfile_acquire(pidfile);
62 setsid();
62 xdaemon(0, 0); 63 xdaemon(0, 0);
63 daemonized++; 64 daemonized++;
65 logmode &= ~LOGMODE_STDIO;
64 pidfile_write_release(pid_fd); 66 pidfile_write_release(pid_fd);
65#endif /* __uClinux__ */ 67#endif /* __uClinux__ */
66} 68}
67 69
68
69#ifdef CONFIG_FEATURE_UDHCP_SYSLOG
70
71void udhcp_logging(int level, const char *fmt, ...)
72{
73 va_list p;
74 va_list p2;
75
76 va_start(p, fmt);
77 __va_copy(p2, p);
78 if (!daemonized) {
79 vprintf(fmt, p);
80 putchar('\n');
81 }
82 vsyslog(level, fmt, p2);
83 va_end(p);
84}
85
86#else
87
88
89static char *syslog_level_msg[] = {
90 [LOG_EMERG] = "EMERGENCY!",
91 [LOG_ALERT] = "ALERT!",
92 [LOG_CRIT] = "critical!",
93 [LOG_WARNING] = "warning",
94 [LOG_ERR] = "error",
95 [LOG_INFO] = "info",
96 [LOG_DEBUG] = "debug"
97};
98
99
100void udhcp_logging(int level, const char *fmt, ...)
101{
102 va_list p;
103
104 va_start(p, fmt);
105 if (!daemonized) {
106 printf("%s, ", syslog_level_msg[level]);
107 vprintf(fmt, p);
108 putchar('\n');
109 }
110 va_end(p);
111}
112#endif
113
114
115void udhcp_start_log_and_pid(const char *client_server, const char *pidfile) 70void udhcp_start_log_and_pid(const char *client_server, const char *pidfile)
116{ 71{
117 int pid_fd; 72 int pid_fd;
@@ -126,8 +81,10 @@ void udhcp_start_log_and_pid(const char *client_server, const char *pidfile)
126 /* equivelent of doing a fflush after every \n */ 81 /* equivelent of doing a fflush after every \n */
127 setlinebuf(stdout); 82 setlinebuf(stdout);
128 83
129 if (ENABLE_FEATURE_UDHCP_SYSLOG) 84 if (ENABLE_FEATURE_UDHCP_SYSLOG) {
130 openlog(client_server, LOG_PID | LOG_CONS, LOG_LOCAL0); 85 openlog(client_server, LOG_PID, LOG_LOCAL0);
86 logmode |= LOGMODE_SYSLOG;
87 }
131 88
132 udhcp_logging(LOG_INFO, "%s (v%s) started", client_server, BB_VER); 89 bb_info_msg("%s (v%s) started", client_server, BB_VER);
133} 90}
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h
index eb73c2162..d5291f2f3 100644
--- a/networking/udhcp/common.h
+++ b/networking/udhcp/common.h
@@ -12,26 +12,12 @@
12 12
13#include "libbb_udhcp.h" 13#include "libbb_udhcp.h"
14 14
15
16enum syslog_levels {
17 LOG_EMERG = 0,
18 LOG_ALERT,
19 LOG_CRIT,
20 LOG_WARNING,
21 LOG_ERR,
22 LOG_INFO,
23 LOG_DEBUG
24};
25#include <syslog.h>
26
27long uptime(void); 15long uptime(void);
28 16
29#define LOG(level, str, args...) udhcp_logging(level, str, ## args)
30
31#if ENABLE_FEATURE_UDHCP_DEBUG 17#if ENABLE_FEATURE_UDHCP_DEBUG
32# define DEBUG(level, str, args...) LOG(level, str, ## args) 18# define DEBUG(str, args...) bb_info_msg(str, ## args)
33#else 19#else
34# define DEBUG(level, str, args...) do {;} while(0) 20# define DEBUG(str, args...) do {;} while(0)
35#endif 21#endif
36 22
37#endif 23#endif
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 989759ab8..5b2612e56 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -65,7 +65,7 @@ struct client_config_t client_config = {
65/* just a little helper */ 65/* just a little helper */
66static void change_mode(int new_mode) 66static void change_mode(int new_mode)
67{ 67{
68 DEBUG(LOG_INFO, "entering %s listen mode", 68 DEBUG("entering %s listen mode",
69 new_mode ? (new_mode == 1 ? "kernel" : "raw") : "none"); 69 new_mode ? (new_mode == 1 ? "kernel" : "raw") : "none");
70 if (fd >= 0) close(fd); 70 if (fd >= 0) close(fd);
71 fd = -1; 71 fd = -1;
@@ -76,7 +76,7 @@ static void change_mode(int new_mode)
76/* perform a renew */ 76/* perform a renew */
77static void perform_renew(void) 77static void perform_renew(void)
78{ 78{
79 LOG(LOG_INFO, "Performing a DHCP renew"); 79 bb_info_msg("Performing a DHCP renew");
80 switch (state) { 80 switch (state) {
81 case BOUND: 81 case BOUND:
82 change_mode(LISTEN_KERNEL); 82 change_mode(LISTEN_KERNEL);
@@ -114,12 +114,12 @@ static void perform_release(void)
114 temp_addr.s_addr = server_addr; 114 temp_addr.s_addr = server_addr;
115 sprintf(buffer, "%s", inet_ntoa(temp_addr)); 115 sprintf(buffer, "%s", inet_ntoa(temp_addr));
116 temp_addr.s_addr = requested_ip; 116 temp_addr.s_addr = requested_ip;
117 LOG(LOG_INFO, "Unicasting a release of %s to %s", 117 bb_info_msg("Unicasting a release of %s to %s",
118 inet_ntoa(temp_addr), buffer); 118 inet_ntoa(temp_addr), buffer);
119 send_release(server_addr, requested_ip); /* unicast */ 119 send_release(server_addr, requested_ip); /* unicast */
120 udhcp_run_script(NULL, "deconfig"); 120 udhcp_run_script(NULL, "deconfig");
121 } 121 }
122 LOG(LOG_INFO, "Entering released state"); 122 bb_info_msg("Entering released state");
123 123
124 change_mode(LISTEN_NONE); 124 change_mode(LISTEN_NONE);
125 state = RELEASED; 125 state = RELEASED;
@@ -310,14 +310,14 @@ int udhcpc_main(int argc, char *argv[])
310 else 310 else
311 fd = raw_socket(client_config.ifindex); 311 fd = raw_socket(client_config.ifindex);
312 if (fd < 0) { 312 if (fd < 0) {
313 LOG(LOG_ERR, "FATAL: couldn't listen on socket, %m"); 313 bb_perror_msg("FATAL: couldn't listen on socket");
314 return 0; 314 return 0;
315 } 315 }
316 } 316 }
317 max_fd = udhcp_sp_fd_set(&rfds, fd); 317 max_fd = udhcp_sp_fd_set(&rfds, fd);
318 318
319 if (tv.tv_sec > 0) { 319 if (tv.tv_sec > 0) {
320 DEBUG(LOG_INFO, "Waiting on select..."); 320 DEBUG("Waiting on select...");
321 retval = select(max_fd + 1, &rfds, NULL, NULL, &tv); 321 retval = select(max_fd + 1, &rfds, NULL, NULL, &tv);
322 } else retval = 0; /* If we already timed out, fall through */ 322 } else retval = 0; /* If we already timed out, fall through */
323 323
@@ -338,10 +338,10 @@ int udhcpc_main(int argc, char *argv[])
338 } else { 338 } else {
339 udhcp_run_script(NULL, "leasefail"); 339 udhcp_run_script(NULL, "leasefail");
340 if (client_config.background_if_no_lease) { 340 if (client_config.background_if_no_lease) {
341 LOG(LOG_INFO, "No lease, forking to background."); 341 bb_info_msg("No lease, forking to background");
342 client_background(); 342 client_background();
343 } else if (client_config.abort_if_no_lease) { 343 } else if (client_config.abort_if_no_lease) {
344 LOG(LOG_INFO, "No lease, failing."); 344 bb_info_msg("No lease, failing");
345 return 1; 345 return 1;
346 } 346 }
347 /* wait to try again */ 347 /* wait to try again */
@@ -372,7 +372,7 @@ int udhcpc_main(int argc, char *argv[])
372 /* Lease is starting to run out, time to enter renewing state */ 372 /* Lease is starting to run out, time to enter renewing state */
373 state = RENEWING; 373 state = RENEWING;
374 change_mode(LISTEN_KERNEL); 374 change_mode(LISTEN_KERNEL);
375 DEBUG(LOG_INFO, "Entering renew state"); 375 DEBUG("Entering renew state");
376 /* fall right through */ 376 /* fall right through */
377 case RENEWING: 377 case RENEWING:
378 /* Either set a new T1, or enter REBINDING state */ 378 /* Either set a new T1, or enter REBINDING state */
@@ -380,7 +380,7 @@ int udhcpc_main(int argc, char *argv[])
380 /* timed out, enter rebinding state */ 380 /* timed out, enter rebinding state */
381 state = REBINDING; 381 state = REBINDING;
382 timeout = now + (t2 - t1); 382 timeout = now + (t2 - t1);
383 DEBUG(LOG_INFO, "Entering rebinding state"); 383 DEBUG("Entering rebinding state");
384 } else { 384 } else {
385 /* send a request packet */ 385 /* send a request packet */
386 send_renew(xid, server_addr, requested_ip); /* unicast */ 386 send_renew(xid, server_addr, requested_ip); /* unicast */
@@ -394,7 +394,7 @@ int udhcpc_main(int argc, char *argv[])
394 if ((lease - t2) <= (lease / 14400 + 1)) { 394 if ((lease - t2) <= (lease / 14400 + 1)) {
395 /* timed out, enter init state */ 395 /* timed out, enter init state */
396 state = INIT_SELECTING; 396 state = INIT_SELECTING;
397 LOG(LOG_INFO, "Lease lost, entering init state"); 397 bb_info_msg("Lease lost, entering init state");
398 udhcp_run_script(NULL, "deconfig"); 398 udhcp_run_script(NULL, "deconfig");
399 timeout = now; 399 timeout = now;
400 packet_num = 0; 400 packet_num = 0;
@@ -420,25 +420,25 @@ int udhcpc_main(int argc, char *argv[])
420 else len = get_raw_packet(&packet, fd); 420 else len = get_raw_packet(&packet, fd);
421 421
422 if (len == -1 && errno != EINTR) { 422 if (len == -1 && errno != EINTR) {
423 DEBUG(LOG_INFO, "error on read, %m, reopening socket"); 423 DEBUG("error on read, %s, reopening socket", strerror(errno));
424 change_mode(listen_mode); /* just close and reopen */ 424 change_mode(listen_mode); /* just close and reopen */
425 } 425 }
426 if (len < 0) continue; 426 if (len < 0) continue;
427 427
428 if (packet.xid != xid) { 428 if (packet.xid != xid) {
429 DEBUG(LOG_INFO, "Ignoring XID %lx (our xid is %lx)", 429 DEBUG("Ignoring XID %lx (our xid is %lx)",
430 (unsigned long) packet.xid, xid); 430 (unsigned long) packet.xid, xid);
431 continue; 431 continue;
432 } 432 }
433 433
434 /* Ignore packets that aren't for us */ 434 /* Ignore packets that aren't for us */
435 if (memcmp(packet.chaddr, client_config.arp, 6)) { 435 if (memcmp(packet.chaddr, client_config.arp, 6)) {
436 DEBUG(LOG_INFO, "packet does not have our chaddr -- ignoring"); 436 DEBUG("Packet does not have our chaddr - ignoring");
437 continue; 437 continue;
438 } 438 }
439 439
440 if ((message = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) { 440 if ((message = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) {
441 DEBUG(LOG_ERR, "couldnt get option from packet -- ignoring"); 441 bb_error_msg("Couldnt get option from packet - ignoring");
442 continue; 442 continue;
443 } 443 }
444 444
@@ -456,7 +456,7 @@ int udhcpc_main(int argc, char *argv[])
456 timeout = now; 456 timeout = now;
457 packet_num = 0; 457 packet_num = 0;
458 } else { 458 } else {
459 DEBUG(LOG_ERR, "No server ID in message"); 459 bb_error_msg("No server ID in message");
460 } 460 }
461 } 461 }
462 break; 462 break;
@@ -466,7 +466,7 @@ int udhcpc_main(int argc, char *argv[])
466 case REBINDING: 466 case REBINDING:
467 if (*message == DHCPACK) { 467 if (*message == DHCPACK) {
468 if (!(temp = get_option(&packet, DHCP_LEASE_TIME))) { 468 if (!(temp = get_option(&packet, DHCP_LEASE_TIME))) {
469 LOG(LOG_ERR, "No lease time with ACK, using 1 hour lease"); 469 bb_error_msg("No lease time with ACK, using 1 hour lease");
470 lease = 60 * 60; 470 lease = 60 * 60;
471 } else { 471 } else {
472 memcpy(&lease, temp, 4); 472 memcpy(&lease, temp, 4);
@@ -479,7 +479,7 @@ int udhcpc_main(int argc, char *argv[])
479 /* little fixed point for n * .875 */ 479 /* little fixed point for n * .875 */
480 t2 = (lease * 0x7) >> 3; 480 t2 = (lease * 0x7) >> 3;
481 temp_addr.s_addr = packet.yiaddr; 481 temp_addr.s_addr = packet.yiaddr;
482 LOG(LOG_INFO, "Lease of %s obtained, lease time %ld", 482 bb_info_msg("Lease of %s obtained, lease time %ld",
483 inet_ntoa(temp_addr), lease); 483 inet_ntoa(temp_addr), lease);
484 start = now; 484 start = now;
485 timeout = t1 + start; 485 timeout = t1 + start;
@@ -496,7 +496,7 @@ int udhcpc_main(int argc, char *argv[])
496 496
497 } else if (*message == DHCPNAK) { 497 } else if (*message == DHCPNAK) {
498 /* return to init state */ 498 /* return to init state */
499 LOG(LOG_INFO, "Received DHCP NAK"); 499 bb_info_msg("Received DHCP NAK");
500 udhcp_run_script(&packet, "nak"); 500 udhcp_run_script(&packet, "nak");
501 if (state != REQUESTING) 501 if (state != REQUESTING)
502 udhcp_run_script(NULL, "deconfig"); 502 udhcp_run_script(NULL, "deconfig");
@@ -519,14 +519,14 @@ int udhcpc_main(int argc, char *argv[])
519 perform_release(); 519 perform_release();
520 break; 520 break;
521 case SIGTERM: 521 case SIGTERM:
522 LOG(LOG_INFO, "Received SIGTERM"); 522 bb_info_msg("Received SIGTERM");
523 return 0; 523 return 0;
524 } 524 }
525 } else if (retval == -1 && errno == EINTR) { 525 } else if (retval == -1 && errno == EINTR) {
526 /* a signal was caught */ 526 /* a signal was caught */
527 } else { 527 } else {
528 /* An error occured */ 528 /* An error occured */
529 DEBUG(LOG_ERR, "Error on select"); 529 bb_perror_msg("select");
530 } 530 }
531 531
532 } 532 }
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index b481e6ef2..8715661b7 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -66,7 +66,7 @@ int udhcpd_main(int argc, char *argv[])
66 /* Sanity check */ 66 /* Sanity check */
67 num_ips = ntohl(server_config.end) - ntohl(server_config.start) + 1; 67 num_ips = ntohl(server_config.end) - ntohl(server_config.start) + 1;
68 if (server_config.max_leases > num_ips) { 68 if (server_config.max_leases > num_ips) {
69 LOG(LOG_ERR, "max_leases value (%lu) not sane, " 69 bb_error_msg("max_leases value (%lu) not sane, "
70 "setting to %lu instead", 70 "setting to %lu instead",
71 server_config.max_leases, num_ips); 71 server_config.max_leases, num_ips);
72 server_config.max_leases = num_ips; 72 server_config.max_leases = num_ips;
@@ -90,7 +90,7 @@ int udhcpd_main(int argc, char *argv[])
90 90
91 if (server_socket < 0) 91 if (server_socket < 0)
92 if ((server_socket = listen_socket(INADDR_ANY, SERVER_PORT, server_config.interface)) < 0) { 92 if ((server_socket = listen_socket(INADDR_ANY, SERVER_PORT, server_config.interface)) < 0) {
93 LOG(LOG_ERR, "FATAL: couldn't create server socket, %m"); 93 bb_perror_msg("FATAL: couldn't create server socket");
94 return 2; 94 return 2;
95 } 95 }
96 96
@@ -109,19 +109,19 @@ int udhcpd_main(int argc, char *argv[])
109 timeout_end = time(0) + server_config.auto_time; 109 timeout_end = time(0) + server_config.auto_time;
110 continue; 110 continue;
111 } else if (retval < 0 && errno != EINTR) { 111 } else if (retval < 0 && errno != EINTR) {
112 DEBUG(LOG_INFO, "error on select"); 112 DEBUG("error on select");
113 continue; 113 continue;
114 } 114 }
115 115
116 switch (udhcp_sp_read(&rfds)) { 116 switch (udhcp_sp_read(&rfds)) {
117 case SIGUSR1: 117 case SIGUSR1:
118 LOG(LOG_INFO, "Received a SIGUSR1"); 118 bb_info_msg("Received a SIGUSR1");
119 write_leases(); 119 write_leases();
120 /* why not just reset the timeout, eh */ 120 /* why not just reset the timeout, eh */
121 timeout_end = time(0) + server_config.auto_time; 121 timeout_end = time(0) + server_config.auto_time;
122 continue; 122 continue;
123 case SIGTERM: 123 case SIGTERM:
124 LOG(LOG_INFO, "Received a SIGTERM"); 124 bb_info_msg("Received a SIGTERM");
125 return 0; 125 return 0;
126 case 0: break; /* no signal */ 126 case 0: break; /* no signal */
127 default: continue; /* signal or error (probably EINTR) */ 127 default: continue; /* signal or error (probably EINTR) */
@@ -129,7 +129,7 @@ int udhcpd_main(int argc, char *argv[])
129 129
130 if ((bytes = udhcp_get_packet(&packet, server_socket)) < 0) { /* this waits for a packet - idle */ 130 if ((bytes = udhcp_get_packet(&packet, server_socket)) < 0) { /* this waits for a packet - idle */
131 if (bytes == -1 && errno != EINTR) { 131 if (bytes == -1 && errno != EINTR) {
132 DEBUG(LOG_INFO, "error on read, %m, reopening socket"); 132 DEBUG("error on read, %s, reopening socket", strerror(errno));
133 close(server_socket); 133 close(server_socket);
134 server_socket = -1; 134 server_socket = -1;
135 } 135 }
@@ -137,7 +137,7 @@ int udhcpd_main(int argc, char *argv[])
137 } 137 }
138 138
139 if ((state = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) { 139 if ((state = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) {
140 DEBUG(LOG_ERR, "couldn't get option from packet, ignoring"); 140 bb_error_msg("Couldn't get option from packet, ignoring");
141 continue; 141 continue;
142 } 142 }
143 143
@@ -146,7 +146,7 @@ int udhcpd_main(int argc, char *argv[])
146 146
147 if(static_lease_ip) 147 if(static_lease_ip)
148 { 148 {
149 printf("Found static lease: %x\n", static_lease_ip); 149 bb_info_msg("Found static lease: %x", static_lease_ip);
150 150
151 memcpy(&static_lease.chaddr, &packet.chaddr, 16); 151 memcpy(&static_lease.chaddr, &packet.chaddr, 16);
152 static_lease.yiaddr = static_lease_ip; 152 static_lease.yiaddr = static_lease_ip;
@@ -162,14 +162,14 @@ int udhcpd_main(int argc, char *argv[])
162 162
163 switch (state[0]) { 163 switch (state[0]) {
164 case DHCPDISCOVER: 164 case DHCPDISCOVER:
165 DEBUG(LOG_INFO,"received DISCOVER"); 165 DEBUG("Received DISCOVER");
166 166
167 if (sendOffer(&packet) < 0) { 167 if (sendOffer(&packet) < 0) {
168 LOG(LOG_ERR, "send OFFER failed"); 168 bb_error_msg("Send OFFER failed");
169 } 169 }
170 break; 170 break;
171 case DHCPREQUEST: 171 case DHCPREQUEST:
172 DEBUG(LOG_INFO, "received REQUEST"); 172 DEBUG("received REQUEST");
173 173
174 requested = get_option(&packet, DHCP_REQUESTED_IP); 174 requested = get_option(&packet, DHCP_REQUESTED_IP);
175 server_id = get_option(&packet, DHCP_SERVER_ID); 175 server_id = get_option(&packet, DHCP_SERVER_ID);
@@ -180,7 +180,7 @@ int udhcpd_main(int argc, char *argv[])
180 if (lease) { 180 if (lease) {
181 if (server_id) { 181 if (server_id) {
182 /* SELECTING State */ 182 /* SELECTING State */
183 DEBUG(LOG_INFO, "server_id = %08x", ntohl(server_id_align)); 183 DEBUG("server_id = %08x", ntohl(server_id_align));
184 if (server_id_align == server_config.server && requested && 184 if (server_id_align == server_config.server && requested &&
185 requested_align == lease->yiaddr) { 185 requested_align == lease->yiaddr) {
186 sendACK(&packet, lease->yiaddr); 186 sendACK(&packet, lease->yiaddr);
@@ -224,22 +224,22 @@ int udhcpd_main(int argc, char *argv[])
224 } 224 }
225 break; 225 break;
226 case DHCPDECLINE: 226 case DHCPDECLINE:
227 DEBUG(LOG_INFO,"received DECLINE"); 227 DEBUG("Received DECLINE");
228 if (lease) { 228 if (lease) {
229 memset(lease->chaddr, 0, 16); 229 memset(lease->chaddr, 0, 16);
230 lease->expires = time(0) + server_config.decline_time; 230 lease->expires = time(0) + server_config.decline_time;
231 } 231 }
232 break; 232 break;
233 case DHCPRELEASE: 233 case DHCPRELEASE:
234 DEBUG(LOG_INFO,"received RELEASE"); 234 DEBUG("Received RELEASE");
235 if (lease) lease->expires = time(0); 235 if (lease) lease->expires = time(0);
236 break; 236 break;
237 case DHCPINFORM: 237 case DHCPINFORM:
238 DEBUG(LOG_INFO,"received INFORM"); 238 DEBUG("Received INFORM");
239 send_inform(&packet); 239 send_inform(&packet);
240 break; 240 break;
241 default: 241 default:
242 LOG(LOG_WARNING, "unsupported DHCP message (%02x) -- ignoring", state[0]); 242 bb_info_msg("Unsupported DHCP message (%02x) - ignoring", state[0]);
243 } 243 }
244 } 244 }
245 245
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c
index a0a3bfcd8..d9dfb8965 100644
--- a/networking/udhcp/files.c
+++ b/networking/udhcp/files.c
@@ -112,7 +112,7 @@ static void attach_option(struct option_set **opt_list, struct dhcp_option *opti
112 112
113 /* add it to an existing option */ 113 /* add it to an existing option */
114 if ((existing = find_option(*opt_list, option->code))) { 114 if ((existing = find_option(*opt_list, option->code))) {
115 DEBUG(LOG_INFO, "Attaching option %s to existing member of list", option->name); 115 DEBUG("Attaching option %s to existing member of list", option->name);
116 if (option->flags & OPTION_LIST) { 116 if (option->flags & OPTION_LIST) {
117 if (existing->data[OPT_LEN] + length <= 255) { 117 if (existing->data[OPT_LEN] + length <= 255) {
118 existing->data = realloc(existing->data, 118 existing->data = realloc(existing->data,
@@ -122,7 +122,7 @@ static void attach_option(struct option_set **opt_list, struct dhcp_option *opti
122 } /* else, ignore the data, we could put this in a second option in the future */ 122 } /* else, ignore the data, we could put this in a second option in the future */
123 } /* else, ignore the new data */ 123 } /* else, ignore the new data */
124 } else { 124 } else {
125 DEBUG(LOG_INFO, "Attaching option %s to list", option->name); 125 DEBUG("Attaching option %s to list", option->name);
126 126
127 /* make a new option */ 127 /* make a new option */
128 new = xmalloc(sizeof(struct option_set)); 128 new = xmalloc(sizeof(struct option_set));
@@ -286,7 +286,7 @@ int read_config(const char *file)
286 keywords[i].handler(keywords[i].def, keywords[i].var); 286 keywords[i].handler(keywords[i].def, keywords[i].var);
287 287
288 if (!(in = fopen(file, "r"))) { 288 if (!(in = fopen(file, "r"))) {
289 LOG(LOG_ERR, "unable to open config file: %s", file); 289 bb_error_msg("Unable to open config file: %s", file);
290 return 0; 290 return 0;
291 } 291 }
292 292
@@ -310,8 +310,9 @@ int read_config(const char *file)
310 for (i = 0; keywords[i].keyword[0]; i++) 310 for (i = 0; keywords[i].keyword[0]; i++)
311 if (!strcasecmp(token, keywords[i].keyword)) 311 if (!strcasecmp(token, keywords[i].keyword))
312 if (!keywords[i].handler(line, keywords[i].var)) { 312 if (!keywords[i].handler(line, keywords[i].var)) {
313 LOG(LOG_ERR, "Failure parsing line %d of %s", lm, file); 313 bb_error_msg("Failure parsing line %d of %s", lm, file);
314 DEBUG(LOG_ERR, "unable to parse '%s'", debug_orig); 314 if (ENABLE_FEATURE_UDHCP_DEBUG)
315 bb_error_msg("unable to parse '%s'", debug_orig);
315 /* reset back to the default value */ 316 /* reset back to the default value */
316 keywords[i].handler(keywords[i].def, keywords[i].var); 317 keywords[i].handler(keywords[i].def, keywords[i].var);
317 } 318 }
@@ -330,7 +331,7 @@ void write_leases(void)
330 unsigned long tmp_time; 331 unsigned long tmp_time;
331 332
332 if (!(fp = fopen(server_config.lease_file, "w"))) { 333 if (!(fp = fopen(server_config.lease_file, "w"))) {
333 LOG(LOG_ERR, "Unable to open %s for writing", server_config.lease_file); 334 bb_error_msg("Unable to open %s for writing", server_config.lease_file);
334 return; 335 return;
335 } 336 }
336 337
@@ -368,7 +369,7 @@ void read_leases(const char *file)
368 struct dhcpOfferedAddr lease; 369 struct dhcpOfferedAddr lease;
369 370
370 if (!(fp = fopen(file, "r"))) { 371 if (!(fp = fopen(file, "r"))) {
371 LOG(LOG_ERR, "Unable to open %s for reading", file); 372 bb_error_msg("Unable to open %s for reading", file);
372 return; 373 return;
373 } 374 }
374 375
@@ -378,12 +379,12 @@ void read_leases(const char *file)
378 lease.expires = ntohl(lease.expires); 379 lease.expires = ntohl(lease.expires);
379 if (!server_config.remaining) lease.expires -= time(0); 380 if (!server_config.remaining) lease.expires -= time(0);
380 if (!(add_lease(lease.chaddr, lease.yiaddr, lease.expires))) { 381 if (!(add_lease(lease.chaddr, lease.yiaddr, lease.expires))) {
381 LOG(LOG_WARNING, "Too many leases while loading %s\n", file); 382 bb_error_msg("Too many leases while loading %s", file);
382 break; 383 break;
383 } 384 }
384 i++; 385 i++;
385 } 386 }
386 } 387 }
387 DEBUG(LOG_INFO, "Read %d leases", i); 388 DEBUG("Read %d leases", i);
388 fclose(fp); 389 fclose(fp);
389} 390}
diff --git a/networking/udhcp/leases.c b/networking/udhcp/leases.c
index 4c69c1f93..f5113408b 100644
--- a/networking/udhcp/leases.c
+++ b/networking/udhcp/leases.c
@@ -113,7 +113,7 @@ static int check_ip(uint32_t addr)
113 113
114 if (arpping(addr, server_config.server, server_config.arp, server_config.interface) == 0) { 114 if (arpping(addr, server_config.server, server_config.arp, server_config.interface) == 0) {
115 temp.s_addr = addr; 115 temp.s_addr = addr;
116 LOG(LOG_INFO, "%s belongs to someone, reserving it for %ld seconds", 116 bb_info_msg("%s belongs to someone, reserving it for %ld seconds",
117 inet_ntoa(temp), server_config.conflict_time); 117 inet_ntoa(temp), server_config.conflict_time);
118 add_lease(blank_chaddr, addr, server_config.conflict_time); 118 add_lease(blank_chaddr, addr, server_config.conflict_time);
119 return 1; 119 return 1;
diff --git a/networking/udhcp/libbb_udhcp.h b/networking/udhcp/libbb_udhcp.h
index c21d3baab..b353876d2 100644
--- a/networking/udhcp/libbb_udhcp.h
+++ b/networking/udhcp/libbb_udhcp.h
@@ -22,7 +22,6 @@
22 22
23void udhcp_background(const char *pidfile); 23void udhcp_background(const char *pidfile);
24void udhcp_start_log_and_pid(const char *client_server, const char *pidfile); 24void udhcp_start_log_and_pid(const char *client_server, const char *pidfile);
25void udhcp_logging(int level, const char *fmt, ...);
26 25
27void udhcp_run_script(struct dhcpMessage *packet, const char *name); 26void udhcp_run_script(struct dhcpMessage *packet, const char *name);
28 27
diff --git a/networking/udhcp/options.c b/networking/udhcp/options.c
index 02c251083..652647229 100644
--- a/networking/udhcp/options.c
+++ b/networking/udhcp/options.c
@@ -73,12 +73,12 @@ uint8_t *get_option(struct dhcpMessage *packet, int code)
73 length = 308; 73 length = 308;
74 while (!done) { 74 while (!done) {
75 if (i >= length) { 75 if (i >= length) {
76 LOG(LOG_WARNING, "bogus packet, option fields too long."); 76 bb_error_msg("Bogus packet, option fields too long");
77 return NULL; 77 return NULL;
78 } 78 }
79 if (optionptr[i + OPT_CODE] == code) { 79 if (optionptr[i + OPT_CODE] == code) {
80 if (i + 1 + optionptr[i + OPT_LEN] >= length) { 80 if (i + 1 + optionptr[i + OPT_LEN] >= length) {
81 LOG(LOG_WARNING, "bogus packet, option fields too long."); 81 bb_error_msg("Bogus packet, option fields too long");
82 return NULL; 82 return NULL;
83 } 83 }
84 return optionptr + i + 2; 84 return optionptr + i + 2;
@@ -89,7 +89,7 @@ uint8_t *get_option(struct dhcpMessage *packet, int code)
89 break; 89 break;
90 case DHCP_OPTION_OVER: 90 case DHCP_OPTION_OVER:
91 if (i + 1 + optionptr[i + OPT_LEN] >= length) { 91 if (i + 1 + optionptr[i + OPT_LEN] >= length) {
92 LOG(LOG_WARNING, "bogus packet, option fields too long."); 92 bb_error_msg("Bogus packet, option fields too long");
93 return NULL; 93 return NULL;
94 } 94 }
95 over = optionptr[i + 3]; 95 over = optionptr[i + 3];
@@ -137,10 +137,11 @@ int add_option_string(uint8_t *optionptr, uint8_t *string)
137 137
138 /* end position + string length + option code/length + end option */ 138 /* end position + string length + option code/length + end option */
139 if (end + string[OPT_LEN] + 2 + 1 >= 308) { 139 if (end + string[OPT_LEN] + 2 + 1 >= 308) {
140 LOG(LOG_ERR, "Option 0x%02x did not fit into the packet!", string[OPT_CODE]); 140 bb_error_msg("Option 0x%02x did not fit into the packet",
141 string[OPT_CODE]);
141 return 0; 142 return 0;
142 } 143 }
143 DEBUG(LOG_INFO, "adding option 0x%02x", string[OPT_CODE]); 144 DEBUG("adding option 0x%02x", string[OPT_CODE]);
144 memcpy(optionptr + end, string, string[OPT_LEN] + 2); 145 memcpy(optionptr + end, string, string[OPT_LEN] + 2);
145 optionptr[end + string[OPT_LEN] + 2] = DHCP_END; 146 optionptr[end + string[OPT_LEN] + 2] = DHCP_END;
146 return string[OPT_LEN] + 2; 147 return string[OPT_LEN] + 2;
@@ -167,6 +168,6 @@ int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data)
167 } 168 }
168 } 169 }
169 170
170 DEBUG(LOG_ERR, "Could not add option 0x%02x", code); 171 bb_error_msg("Could not add option 0x%02x", code);
171 return 0; 172 return 0;
172} 173}
diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c
index 67a452dbc..30675eaab 100644
--- a/networking/udhcp/packet.c
+++ b/networking/udhcp/packet.c
@@ -58,21 +58,21 @@ int udhcp_get_packet(struct dhcpMessage *packet, int fd)
58 memset(packet, 0, sizeof(struct dhcpMessage)); 58 memset(packet, 0, sizeof(struct dhcpMessage));
59 bytes = read(fd, packet, sizeof(struct dhcpMessage)); 59 bytes = read(fd, packet, sizeof(struct dhcpMessage));
60 if (bytes < 0) { 60 if (bytes < 0) {
61 DEBUG(LOG_INFO, "couldn't read on listening socket, ignoring"); 61 DEBUG("couldn't read on listening socket, ignoring");
62 return -1; 62 return -1;
63 } 63 }
64 64
65 if (ntohl(packet->cookie) != DHCP_MAGIC) { 65 if (ntohl(packet->cookie) != DHCP_MAGIC) {
66 LOG(LOG_ERR, "received bogus message, ignoring"); 66 bb_error_msg("Received bogus message, ignoring");
67 return -2; 67 return -2;
68 } 68 }
69 DEBUG(LOG_INFO, "Received a packet"); 69 DEBUG("Received a packet");
70 70
71 if (packet->op == BOOTREQUEST && (vendor = get_option(packet, DHCP_VENDOR))) { 71 if (packet->op == BOOTREQUEST && (vendor = get_option(packet, DHCP_VENDOR))) {
72 for (i = 0; broken_vendors[i][0]; i++) { 72 for (i = 0; broken_vendors[i][0]; i++) {
73 if (vendor[OPT_LEN - 2] == (uint8_t) strlen(broken_vendors[i]) && 73 if (vendor[OPT_LEN - 2] == (uint8_t) strlen(broken_vendors[i]) &&
74 !strncmp((char*)vendor, broken_vendors[i], vendor[OPT_LEN - 2])) { 74 !strncmp((char*)vendor, broken_vendors[i], vendor[OPT_LEN - 2])) {
75 DEBUG(LOG_INFO, "broken client (%s), forcing broadcast", 75 DEBUG("broken client (%s), forcing broadcast",
76 broken_vendors[i]); 76 broken_vendors[i]);
77 packet->flags |= htons(BROADCAST_FLAG); 77 packet->flags |= htons(BROADCAST_FLAG);
78 } 78 }
@@ -123,7 +123,7 @@ int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source
123 struct udp_dhcp_packet packet; 123 struct udp_dhcp_packet packet;
124 124
125 if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) { 125 if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) {
126 DEBUG(LOG_ERR, "socket call failed: %m"); 126 bb_perror_msg("socket");
127 return -1; 127 return -1;
128 } 128 }
129 129
@@ -136,7 +136,7 @@ int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source
136 dest.sll_halen = 6; 136 dest.sll_halen = 6;
137 memcpy(dest.sll_addr, dest_arp, 6); 137 memcpy(dest.sll_addr, dest_arp, 6);
138 if (bind(fd, (struct sockaddr *)&dest, sizeof(struct sockaddr_ll)) < 0) { 138 if (bind(fd, (struct sockaddr *)&dest, sizeof(struct sockaddr_ll)) < 0) {
139 DEBUG(LOG_ERR, "bind call failed: %m"); 139 bb_perror_msg("bind");
140 close(fd); 140 close(fd);
141 return -1; 141 return -1;
142 } 142 }
@@ -159,7 +159,7 @@ int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source
159 159
160 result = sendto(fd, &packet, sizeof(struct udp_dhcp_packet), 0, (struct sockaddr *) &dest, sizeof(dest)); 160 result = sendto(fd, &packet, sizeof(struct udp_dhcp_packet), 0, (struct sockaddr *) &dest, sizeof(dest));
161 if (result <= 0) { 161 if (result <= 0) {
162 DEBUG(LOG_ERR, "write on socket failed: %m"); 162 bb_perror_msg("sendto");
163 } 163 }
164 close(fd); 164 close(fd);
165 return result; 165 return result;
diff --git a/networking/udhcp/pidfile.c b/networking/udhcp/pidfile.c
index b837270fb..148b07b34 100644
--- a/networking/udhcp/pidfile.c
+++ b/networking/udhcp/pidfile.c
@@ -45,7 +45,7 @@ int pidfile_acquire(const char *pidfile)
45 45
46 pid_fd = open(pidfile, O_CREAT | O_WRONLY, 0644); 46 pid_fd = open(pidfile, O_CREAT | O_WRONLY, 0644);
47 if (pid_fd < 0) { 47 if (pid_fd < 0) {
48 LOG(LOG_ERR, "Unable to open pidfile %s: %m\n", pidfile); 48 bb_perror_msg("Unable to open pidfile %s", pidfile);
49 } else { 49 } else {
50 lockf(pid_fd, F_LOCK, 0); 50 lockf(pid_fd, F_LOCK, 0);
51 if (!saved_pidfile) 51 if (!saved_pidfile)
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c
index 5a4b33a53..3c4b51b24 100644
--- a/networking/udhcp/script.c
+++ b/networking/udhcp/script.c
@@ -200,7 +200,7 @@ void udhcp_run_script(struct dhcpMessage *packet, const char *name)
200 if (client_config.script == NULL) 200 if (client_config.script == NULL)
201 return; 201 return;
202 202
203 DEBUG(LOG_INFO, "vforking and execle'ing %s", client_config.script); 203 DEBUG("vfork'ing and execle'ing %s", client_config.script);
204 204
205 envp = fill_envp(packet); 205 envp = fill_envp(packet);
206 /* call script */ 206 /* call script */
@@ -216,7 +216,7 @@ void udhcp_run_script(struct dhcpMessage *packet, const char *name)
216 /* exec script */ 216 /* exec script */
217 execle(client_config.script, client_config.script, 217 execle(client_config.script, client_config.script,
218 name, NULL, envp); 218 name, NULL, envp);
219 LOG(LOG_ERR, "script %s failed: %m", client_config.script); 219 bb_perror_msg("script %s failed", client_config.script);
220 exit(1); 220 exit(1);
221 } 221 }
222} 222}
diff --git a/networking/udhcp/serverpacket.c b/networking/udhcp/serverpacket.c
index 8c7b1642a..cfead413c 100644
--- a/networking/udhcp/serverpacket.c
+++ b/networking/udhcp/serverpacket.c
@@ -35,7 +35,7 @@
35/* send a packet to giaddr using the kernel ip stack */ 35/* send a packet to giaddr using the kernel ip stack */
36static int send_packet_to_relay(struct dhcpMessage *payload) 36static int send_packet_to_relay(struct dhcpMessage *payload)
37{ 37{
38 DEBUG(LOG_INFO, "Forwarding packet to relay"); 38 DEBUG("Forwarding packet to relay");
39 39
40 return udhcp_kernel_packet(payload, server_config.server, SERVER_PORT, 40 return udhcp_kernel_packet(payload, server_config.server, SERVER_PORT,
41 payload->giaddr, SERVER_PORT); 41 payload->giaddr, SERVER_PORT);
@@ -49,19 +49,19 @@ static int send_packet_to_client(struct dhcpMessage *payload, int force_broadcas
49 uint32_t ciaddr; 49 uint32_t ciaddr;
50 50
51 if (force_broadcast) { 51 if (force_broadcast) {
52 DEBUG(LOG_INFO, "broadcasting packet to client (NAK)"); 52 DEBUG("broadcasting packet to client (NAK)");
53 ciaddr = INADDR_BROADCAST; 53 ciaddr = INADDR_BROADCAST;
54 chaddr = MAC_BCAST_ADDR; 54 chaddr = MAC_BCAST_ADDR;
55 } else if (payload->ciaddr) { 55 } else if (payload->ciaddr) {
56 DEBUG(LOG_INFO, "unicasting packet to client ciaddr"); 56 DEBUG("unicasting packet to client ciaddr");
57 ciaddr = payload->ciaddr; 57 ciaddr = payload->ciaddr;
58 chaddr = payload->chaddr; 58 chaddr = payload->chaddr;
59 } else if (ntohs(payload->flags) & BROADCAST_FLAG) { 59 } else if (ntohs(payload->flags) & BROADCAST_FLAG) {
60 DEBUG(LOG_INFO, "broadcasting packet to client (requested)"); 60 DEBUG("broadcasting packet to client (requested)");
61 ciaddr = INADDR_BROADCAST; 61 ciaddr = INADDR_BROADCAST;
62 chaddr = MAC_BCAST_ADDR; 62 chaddr = MAC_BCAST_ADDR;
63 } else { 63 } else {
64 DEBUG(LOG_INFO, "unicasting packet to client yiaddr"); 64 DEBUG("unicasting packet to client yiaddr");
65 ciaddr = payload->yiaddr; 65 ciaddr = payload->yiaddr;
66 chaddr = payload->chaddr; 66 chaddr = payload->chaddr;
67 } 67 }
@@ -158,12 +158,12 @@ int sendOffer(struct dhcpMessage *oldpacket)
158 } 158 }
159 159
160 if(!packet.yiaddr) { 160 if(!packet.yiaddr) {
161 LOG(LOG_WARNING, "no IP addresses to give -- OFFER abandoned"); 161 bb_error_msg("No IP addresses to give - OFFER abandoned");
162 return -1; 162 return -1;
163 } 163 }
164 164
165 if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time)) { 165 if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time)) {
166 LOG(LOG_WARNING, "lease pool is full -- OFFER abandoned"); 166 bb_error_msg("Lease pool is full - OFFER abandoned");
167 return -1; 167 return -1;
168 } 168 }
169 169
@@ -197,7 +197,7 @@ int sendOffer(struct dhcpMessage *oldpacket)
197 add_bootp_options(&packet); 197 add_bootp_options(&packet);
198 198
199 addr.s_addr = packet.yiaddr; 199 addr.s_addr = packet.yiaddr;
200 LOG(LOG_INFO, "sending OFFER of %s", inet_ntoa(addr)); 200 bb_info_msg("Sending OFFER of %s", inet_ntoa(addr));
201 return send_packet(&packet, 0); 201 return send_packet(&packet, 0);
202} 202}
203 203
@@ -208,7 +208,7 @@ int sendNAK(struct dhcpMessage *oldpacket)
208 208
209 init_packet(&packet, oldpacket, DHCPNAK); 209 init_packet(&packet, oldpacket, DHCPNAK);
210 210
211 DEBUG(LOG_INFO, "sending NAK"); 211 DEBUG("Sending NAK");
212 return send_packet(&packet, 1); 212 return send_packet(&packet, 1);
213} 213}
214 214
@@ -245,7 +245,7 @@ int sendACK(struct dhcpMessage *oldpacket, uint32_t yiaddr)
245 add_bootp_options(&packet); 245 add_bootp_options(&packet);
246 246
247 addr.s_addr = packet.yiaddr; 247 addr.s_addr = packet.yiaddr;
248 LOG(LOG_INFO, "sending ACK to %s", inet_ntoa(addr)); 248 bb_info_msg("Sending ACK to %s", inet_ntoa(addr));
249 249
250 if (send_packet(&packet, 0) < 0) 250 if (send_packet(&packet, 0) < 0)
251 return -1; 251 return -1;
diff --git a/networking/udhcp/signalpipe.c b/networking/udhcp/signalpipe.c
index 9951eb57d..6c4a9f1f2 100644
--- a/networking/udhcp/signalpipe.c
+++ b/networking/udhcp/signalpipe.c
@@ -36,7 +36,7 @@ static int signal_pipe[2];
36static void signal_handler(int sig) 36static void signal_handler(int sig)
37{ 37{
38 if (send(signal_pipe[1], &sig, sizeof(sig), MSG_DONTWAIT) < 0) 38 if (send(signal_pipe[1], &sig, sizeof(sig), MSG_DONTWAIT) < 0)
39 DEBUG(LOG_ERR, "Could not send signal: %m"); 39 bb_perror_msg("Could not send signal");
40} 40}
41 41
42 42
diff --git a/networking/udhcp/socket.c b/networking/udhcp/socket.c
index 2d253c1f2..3f481c33c 100644
--- a/networking/udhcp/socket.c
+++ b/networking/udhcp/socket.c
@@ -60,33 +60,33 @@ int read_interface(char *interface, int *ifindex, uint32_t *addr, uint8_t *arp)
60 if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) { 60 if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
61 our_ip = (struct sockaddr_in *) &ifr.ifr_addr; 61 our_ip = (struct sockaddr_in *) &ifr.ifr_addr;
62 *addr = our_ip->sin_addr.s_addr; 62 *addr = our_ip->sin_addr.s_addr;
63 DEBUG(LOG_INFO, "%s (our ip) = %s", ifr.ifr_name, inet_ntoa(our_ip->sin_addr)); 63 DEBUG("%s (our ip) = %s", ifr.ifr_name, inet_ntoa(our_ip->sin_addr));
64 } else { 64 } else {
65 LOG(LOG_ERR, "SIOCGIFADDR failed, is the interface up and configured?: %m"); 65 bb_perror_msg("SIOCGIFADDR failed, is the interface up and configured?");
66 close(fd); 66 close(fd);
67 return -1; 67 return -1;
68 } 68 }
69 } 69 }
70 70
71 if (ioctl(fd, SIOCGIFINDEX, &ifr) == 0) { 71 if (ioctl(fd, SIOCGIFINDEX, &ifr) == 0) {
72 DEBUG(LOG_INFO, "adapter index %d", ifr.ifr_ifindex); 72 DEBUG("adapter index %d", ifr.ifr_ifindex);
73 *ifindex = ifr.ifr_ifindex; 73 *ifindex = ifr.ifr_ifindex;
74 } else { 74 } else {
75 LOG(LOG_ERR, "SIOCGIFINDEX failed!: %m"); 75 bb_perror_msg("SIOCGIFINDEX failed");
76 close(fd); 76 close(fd);
77 return -1; 77 return -1;
78 } 78 }
79 if (ioctl(fd, SIOCGIFHWADDR, &ifr) == 0) { 79 if (ioctl(fd, SIOCGIFHWADDR, &ifr) == 0) {
80 memcpy(arp, ifr.ifr_hwaddr.sa_data, 6); 80 memcpy(arp, ifr.ifr_hwaddr.sa_data, 6);
81 DEBUG(LOG_INFO, "adapter hardware address %02x:%02x:%02x:%02x:%02x:%02x", 81 DEBUG("adapter hardware address %02x:%02x:%02x:%02x:%02x:%02x",
82 arp[0], arp[1], arp[2], arp[3], arp[4], arp[5]); 82 arp[0], arp[1], arp[2], arp[3], arp[4], arp[5]);
83 } else { 83 } else {
84 LOG(LOG_ERR, "SIOCGIFHWADDR failed!: %m"); 84 bb_perror_msg("SIOCGIFHWADDR failed");
85 close(fd); 85 close(fd);
86 return -1; 86 return -1;
87 } 87 }
88 } else { 88 } else {
89 LOG(LOG_ERR, "socket failed!: %m"); 89 bb_perror_msg("socket failed");
90 return -1; 90 return -1;
91 } 91 }
92 close(fd); 92 close(fd);
@@ -101,9 +101,9 @@ int listen_socket(uint32_t ip, int port, char *inf)
101 struct sockaddr_in addr; 101 struct sockaddr_in addr;
102 int n = 1; 102 int n = 1;
103 103
104 DEBUG(LOG_INFO, "Opening listen socket on 0x%08x:%d %s", ip, port, inf); 104 DEBUG("Opening listen socket on 0x%08x:%d %s", ip, port, inf);
105 if ((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { 105 if ((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
106 DEBUG(LOG_ERR, "socket call failed: %m"); 106 bb_perror_msg("socket");
107 return -1; 107 return -1;
108 } 108 }
109 109
diff --git a/networking/vconfig.c b/networking/vconfig.c
index b90f41085..efbb5a1dc 100644
--- a/networking/vconfig.c
+++ b/networking/vconfig.c
@@ -133,7 +133,7 @@ int vconfig_main(int argc, char **argv)
133 ifr.u.name_type = *xfind_str(name_types+1, argv[1]); 133 ifr.u.name_type = *xfind_str(name_types+1, argv[1]);
134 } else { 134 } else {
135 if (strlen(argv[1]) >= IF_NAMESIZE) { 135 if (strlen(argv[1]) >= IF_NAMESIZE) {
136 bb_error_msg_and_die("if_name >= %d chars\n", IF_NAMESIZE); 136 bb_error_msg_and_die("if_name >= %d chars", IF_NAMESIZE);
137 } 137 }
138 strcpy(ifr.device1, argv[1]); 138 strcpy(ifr.device1, argv[1]);
139 p = argv[2]; 139 p = argv[2];
diff --git a/networking/zcip.c b/networking/zcip.c
index 3a08382c2..5d2a5f786 100644
--- a/networking/zcip.c
+++ b/networking/zcip.c
@@ -124,10 +124,7 @@ static void arp(int fd, struct sockaddr *saddr, int op,
124 124
125 // send it 125 // send it
126 if (sendto(fd, &p, sizeof (p), 0, saddr, sizeof (*saddr)) < 0) { 126 if (sendto(fd, &p, sizeof (p), 0, saddr, sizeof (*saddr)) < 0) {
127 if (FOREGROUND) 127 bb_perror_msg("sendto");
128 perror("sendto");
129 else
130 syslog(LOG_ERR, "sendto: %s", strerror(errno));
131 //return -errno; 128 //return -errno;
132 } 129 }
133 // Currently all callers ignore errors, that's why returns are 130 // Currently all callers ignore errors, that's why returns are
@@ -148,8 +145,7 @@ static int run(char *script, char *arg, char *intf, struct in_addr *ip)
148 if (ip != NULL) { 145 if (ip != NULL) {
149 char *addr = inet_ntoa(*ip); 146 char *addr = inet_ntoa(*ip);
150 setenv("ip", addr, 1); 147 setenv("ip", addr, 1);
151 if (!FOREGROUND) 148 bb_info_msg("%s %s %s", arg, intf, addr);
152 syslog(LOG_INFO, "%s %s %s", arg, intf, addr);
153 } 149 }
154 150
155 pid = vfork(); 151 pid = vfork();
@@ -158,10 +154,7 @@ static int run(char *script, char *arg, char *intf, struct in_addr *ip)
158 goto bad; 154 goto bad;
159 } else if (pid == 0) { // child 155 } else if (pid == 0) { // child
160 execl(script, script, arg, NULL); 156 execl(script, script, arg, NULL);
161 if (FOREGROUND) 157 bb_perror_msg("execl");
162 perror("execl");
163 else
164 syslog(LOG_ERR, "execl: %s", strerror(errno));
165 _exit(EXIT_FAILURE); 158 _exit(EXIT_FAILURE);
166 } 159 }
167 160
@@ -170,24 +163,15 @@ static int run(char *script, char *arg, char *intf, struct in_addr *ip)
170 goto bad; 163 goto bad;
171 } 164 }
172 if (WEXITSTATUS(status) != 0) { 165 if (WEXITSTATUS(status) != 0) {
173 if (FOREGROUND) 166 bb_error_msg("script %s failed, exit=%d",
174 bb_error_msg("script %s failed, exit=%d", 167 script, WEXITSTATUS(status));
175 script, WEXITSTATUS(status));
176 else
177 syslog(LOG_ERR, "script %s failed, exit=%d",
178 script, WEXITSTATUS(status));
179 return -errno; 168 return -errno;
180 } 169 }
181 } 170 }
182 return 0; 171 return 0;
183bad: 172bad:
184 status = -errno; 173 status = -errno;
185 if (FOREGROUND) 174 bb_perror_msg("%s %s, %s", arg, intf, why);
186 bb_perror_msg("%s %s, %s",
187 arg, intf, why);
188 else
189 syslog(LOG_ERR, "%s %s, %s: %s",
190 arg, intf, why, strerror(errno));
191 return status; 175 return status;
192} 176}
193 177
@@ -235,6 +219,11 @@ int zcip_main(int argc, char *argv[])
235 char *r_opt; 219 char *r_opt;
236 bb_opt_complementally = "vv:vf"; // -v accumulates and implies -f 220 bb_opt_complementally = "vv:vf"; // -v accumulates and implies -f
237 opts = bb_getopt_ulflags(argc, argv, "fqr:v", &r_opt, &verbose); 221 opts = bb_getopt_ulflags(argc, argv, "fqr:v", &r_opt, &verbose);
222 if (!FOREGROUND) {
223 /* Do it early, before all bb_xx_msg calls */
224 logmode = LOGMODE_SYSLOG;
225 openlog(bb_applet_name, 0, LOG_DAEMON);
226 }
238 if (opts & 4) { // -r n.n.n.n 227 if (opts & 4) { // -r n.n.n.n
239 if (inet_aton(r_opt, &ip) == 0 228 if (inet_aton(r_opt, &ip) == 0
240 || (ntohl(ip.s_addr) & IN_CLASSB_NET) != LINKLOCAL_ADDR) { 229 || (ntohl(ip.s_addr) & IN_CLASSB_NET) != LINKLOCAL_ADDR) {
@@ -285,9 +274,9 @@ int zcip_main(int argc, char *argv[])
285 274
286 // daemonize now; don't delay system startup 275 // daemonize now; don't delay system startup
287 if (!FOREGROUND) { 276 if (!FOREGROUND) {
288 xdaemon(0, verbose); 277 setsid();
289 openlog(bb_applet_name, 0, LOG_DAEMON); 278 xdaemon(0, 0);
290 syslog(LOG_INFO, "start, interface %s", intf); 279 bb_info_msg("start, interface %s", intf);
291 } 280 }
292 281
293 // run the dynamic address negotiation protocol, 282 // run the dynamic address negotiation protocol,
@@ -557,10 +546,6 @@ int zcip_main(int argc, char *argv[])
557 } // switch poll 546 } // switch poll
558 } 547 }
559bad: 548bad:
560 if (FOREGROUND) 549 bb_perror_msg("%s, %s", intf, why);
561 perror(why);
562 else
563 syslog(LOG_ERR, "%s %s, %s error: %s",
564 bb_applet_name, intf, why, strerror(errno));
565 return EXIT_FAILURE; 550 return EXIT_FAILURE;
566} 551}