diff options
author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2006-04-12 18:09:26 +0000 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2006-04-12 18:09:26 +0000 |
commit | 2c99851181a652358aa3ca58ef38c57e46ae02e4 (patch) | |
tree | 6893f7992748817b64ec66947adc2ca40e13fb8e | |
parent | dac7ff15b7d32deeeef3d9665744fc5774c21d70 (diff) | |
download | busybox-w32-2c99851181a652358aa3ca58ef38c57e46ae02e4.tar.gz busybox-w32-2c99851181a652358aa3ca58ef38c57e46ae02e4.tar.bz2 busybox-w32-2c99851181a652358aa3ca58ef38c57e46ae02e4.zip |
- patch from Denis Vlasenko to add and use bb_xdaemon()
-rw-r--r-- | debianutils/start_stop_daemon.c | 3 | ||||
-rw-r--r-- | include/libbb.h | 1 | ||||
-rw-r--r-- | libbb/Makefile.in | 2 | ||||
-rw-r--r-- | libbb/bb_xdaemon.c | 17 | ||||
-rw-r--r-- | miscutils/crond.c | 5 | ||||
-rw-r--r-- | miscutils/watchdog.c | 3 | ||||
-rw-r--r-- | networking/dnsd.c | 5 | ||||
-rw-r--r-- | networking/httpd.c | 4 | ||||
-rw-r--r-- | networking/inetd.c | 3 | ||||
-rw-r--r-- | networking/telnetd.c | 6 | ||||
-rw-r--r-- | sysklogd/klogd.c | 3 | ||||
-rw-r--r-- | sysklogd/syslogd.c | 3 |
12 files changed, 33 insertions, 22 deletions
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c index 5b689740e..b44a23b4b 100644 --- a/debianutils/start_stop_daemon.c +++ b/debianutils/start_stop_daemon.c | |||
@@ -275,8 +275,7 @@ start_stop_daemon_main(int argc, char **argv) | |||
275 | } | 275 | } |
276 | *--argv = startas; | 276 | *--argv = startas; |
277 | if (opt & SSD_OPT_BACKGROUND) { | 277 | if (opt & SSD_OPT_BACKGROUND) { |
278 | if (daemon(0, 0) == -1) | 278 | bb_xdaemon(0, 0); |
279 | bb_perror_msg_and_die ("unable to fork"); | ||
280 | setsid(); | 279 | setsid(); |
281 | } | 280 | } |
282 | if (opt & SSD_OPT_MAKEPID) { | 281 | if (opt & SSD_OPT_MAKEPID) { |
diff --git a/include/libbb.h b/include/libbb.h index c031f2841..650002b7b 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -146,6 +146,7 @@ extern void bb_fflush_stdout_and_exit(int retval) ATTRIBUTE_NORETURN; | |||
146 | 146 | ||
147 | extern void xstat(const char *filename, struct stat *buf); | 147 | extern void xstat(const char *filename, struct stat *buf); |
148 | extern int bb_xsocket(int domain, int type, int protocol); | 148 | extern int bb_xsocket(int domain, int type, int protocol); |
149 | extern void bb_xdaemon(int nochdir, int noclose); | ||
149 | 150 | ||
150 | #define BB_GETOPT_ERROR 0x80000000UL | 151 | #define BB_GETOPT_ERROR 0x80000000UL |
151 | extern const char *bb_opt_complementally; | 152 | extern const char *bb_opt_complementally; |
diff --git a/libbb/Makefile.in b/libbb/Makefile.in index c69978370..3fb945e31 100644 --- a/libbb/Makefile.in +++ b/libbb/Makefile.in | |||
@@ -30,7 +30,7 @@ LIBBB-y:= \ | |||
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 | vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \ | 31 | vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \ |
32 | xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \ | 32 | xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \ |
33 | bb_xsocket.c \ | 33 | bb_xsocket.c bb_xdaemon.c \ |
34 | 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 \ |
35 | getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \ | 35 | getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \ |
36 | perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \ | 36 | perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \ |
diff --git a/libbb/bb_xdaemon.c b/libbb/bb_xdaemon.c new file mode 100644 index 000000000..a40f4f993 --- /dev/null +++ b/libbb/bb_xdaemon.c | |||
@@ -0,0 +1,17 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * bb_xdaemon.c - a daemon() which dies on failure with error message | ||
4 | * | ||
5 | * Copyright (C) 2006 Denis Vlasenko | ||
6 | * | ||
7 | * Licensed under LGPL, see file docs/lesser.txt in this tarball for details. | ||
8 | */ | ||
9 | #include <unistd.h> | ||
10 | #include "libbb.h" | ||
11 | |||
12 | void bb_xdaemon(int nochdir, int noclose) | ||
13 | { | ||
14 | if (daemon(nochdir, noclose)) | ||
15 | bb_perror_msg_and_die("daemon"); | ||
16 | } | ||
17 | |||
diff --git a/miscutils/crond.c b/miscutils/crond.c index 7e50b61c7..06b8769fa 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
1 | /* | 2 | /* |
2 | * crond -d[#] -c <crondir> -f -b | 3 | * crond -d[#] -c <crondir> -f -b |
3 | * | 4 | * |
@@ -213,9 +214,7 @@ int crond_main(int ac, char **av) | |||
213 | /* reexec for vfork() do continue parent */ | 214 | /* reexec for vfork() do continue parent */ |
214 | vfork_daemon_rexec(1, 0, ac, av, "-f"); | 215 | vfork_daemon_rexec(1, 0, ac, av, "-f"); |
215 | #else /* uClinux */ | 216 | #else /* uClinux */ |
216 | if (daemon(1, 0) < 0) { | 217 | bb_xdaemon(1, 0); |
217 | bb_perror_msg_and_die("daemon"); | ||
218 | } | ||
219 | #endif /* uClinux */ | 218 | #endif /* uClinux */ |
220 | } | 219 | } |
221 | 220 | ||
diff --git a/miscutils/watchdog.c b/miscutils/watchdog.c index 55dd69857..58a606553 100644 --- a/miscutils/watchdog.c +++ b/miscutils/watchdog.c | |||
@@ -40,8 +40,7 @@ int watchdog_main(int argc, char **argv) | |||
40 | if (optind < argc - 1 || argc == 1) | 40 | if (optind < argc - 1 || argc == 1) |
41 | bb_show_usage(); | 41 | bb_show_usage(); |
42 | 42 | ||
43 | if (daemon(0, 1) < 0) | 43 | bb_xdaemon(0, 1); |
44 | bb_perror_msg_and_die("Failed forking watchdog daemon"); | ||
45 | 44 | ||
46 | signal(SIGHUP, watchdog_shutdown); | 45 | signal(SIGHUP, watchdog_shutdown); |
47 | signal(SIGINT, watchdog_shutdown); | 46 | signal(SIGINT, watchdog_shutdown); |
diff --git a/networking/dnsd.c b/networking/dnsd.c index 9c5193820..d78ea04c0 100644 --- a/networking/dnsd.c +++ b/networking/dnsd.c | |||
@@ -5,6 +5,7 @@ | |||
5 | * Copyright (C) 2005 Roberto A. Foglietta (me@roberto.foglietta.name) | 5 | * Copyright (C) 2005 Roberto A. Foglietta (me@roberto.foglietta.name) |
6 | * Copyright (C) 2005 Odd Arild Olsen (oao at fibula dot no) | 6 | * Copyright (C) 2005 Odd Arild Olsen (oao at fibula dot no) |
7 | * Copyright (C) 2003 Paul Sheer | 7 | * Copyright (C) 2003 Paul Sheer |
8 | * | ||
8 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 9 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
9 | * | 10 | * |
10 | * Odd Arild Olsen started out with the sheerdns [1] of Paul Sheer and rewrote | 11 | * Odd Arild Olsen started out with the sheerdns [1] of Paul Sheer and rewrote |
@@ -408,9 +409,7 @@ int dnsd_main(int argc, char **argv) | |||
408 | /* reexec for vfork() do continue parent */ | 409 | /* reexec for vfork() do continue parent */ |
409 | vfork_daemon_rexec(1, 0, argc, argv, "-d"); | 410 | vfork_daemon_rexec(1, 0, argc, argv, "-d"); |
410 | #else /* uClinux */ | 411 | #else /* uClinux */ |
411 | if (daemon(1, 0) < 0) { | 412 | bb_xdaemon(1, 0); |
412 | bb_perror_msg_and_die("daemon"); | ||
413 | } | ||
414 | #endif /* uClinuvx */ | 413 | #endif /* uClinuvx */ |
415 | 414 | ||
416 | dnsentryinit(is_verbose()); | 415 | dnsentryinit(is_verbose()); |
diff --git a/networking/httpd.c b/networking/httpd.c index fde8ae4bd..354c199e7 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
1 | /* | 2 | /* |
2 | * httpd implementation for busybox | 3 | * httpd implementation for busybox |
3 | * | 4 | * |
@@ -2114,8 +2115,7 @@ int httpd_main(int argc, char *argv[]) | |||
2114 | 2115 | ||
2115 | #if !ENABLE_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY | 2116 | #if !ENABLE_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY |
2116 | # if !DEBUG | 2117 | # if !DEBUG |
2117 | if (daemon(1, 0) < 0) /* don`t change curent directory */ | 2118 | bb_xdaemon(1, 0); /* don`t change curent directory */ |
2118 | bb_perror_msg_and_die("daemon"); | ||
2119 | # endif | 2119 | # endif |
2120 | return miniHttpd(server); | 2120 | return miniHttpd(server); |
2121 | #else | 2121 | #else |
diff --git a/networking/inetd.c b/networking/inetd.c index cc700832c..39a2b24cb 100644 --- a/networking/inetd.c +++ b/networking/inetd.c | |||
@@ -1314,7 +1314,7 @@ inetd_main (int argc, char *argv[]) | |||
1314 | /* reexec for vfork() do continue parent */ | 1314 | /* reexec for vfork() do continue parent */ |
1315 | vfork_daemon_rexec (0, 0, argc, argv, "-f"); | 1315 | vfork_daemon_rexec (0, 0, argc, argv, "-f"); |
1316 | #else | 1316 | #else |
1317 | daemon (0, 0); | 1317 | daemon (0, 0); /* bb_xdaemon? */ |
1318 | #endif /* uClinux */ | 1318 | #endif /* uClinux */ |
1319 | } else { | 1319 | } else { |
1320 | setsid (); | 1320 | setsid (); |
@@ -1802,3 +1802,4 @@ daytime_dg (int s, servtab_t *sep ATTRIBUTE_UNUSED) | |||
1802 | (void) sendto (s, buffer, strlen (buffer), 0, &sa, sizeof (sa)); | 1802 | (void) sendto (s, buffer, strlen (buffer), 0, &sa, sizeof (sa)); |
1803 | } | 1803 | } |
1804 | #endif /* CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DAYTIME */ | 1804 | #endif /* CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DAYTIME */ |
1805 | /* vi: set sw=4 ts=4: */ | ||
diff --git a/networking/telnetd.c b/networking/telnetd.c index 3e4b42cfa..d53f56b14 100644 --- a/networking/telnetd.c +++ b/networking/telnetd.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* vi:set ts=4:*/ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * Simple telnet server | 3 | * Simple telnet server |
4 | * Bjorn Wesen, Axis Communications AB (bjornw@axis.com) | 4 | * Bjorn Wesen, Axis Communications AB (bjornw@axis.com) |
@@ -469,9 +469,7 @@ telnetd_main(int argc, char **argv) | |||
469 | bb_perror_msg_and_die("listen"); | 469 | bb_perror_msg_and_die("listen"); |
470 | } | 470 | } |
471 | 471 | ||
472 | if (daemon(0, 0) < 0) | 472 | bb_xdaemon(0, 0); |
473 | bb_perror_msg_and_die("daemon"); | ||
474 | |||
475 | 473 | ||
476 | maxfd = master_fd; | 474 | maxfd = master_fd; |
477 | #endif /* CONFIG_FEATURE_TELNETD_INETD */ | 475 | #endif /* CONFIG_FEATURE_TELNETD_INETD */ |
diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c index 51b01430e..6dc5457af 100644 --- a/sysklogd/klogd.c +++ b/sysklogd/klogd.c | |||
@@ -121,8 +121,7 @@ int klogd_main(int argc, char **argv) | |||
121 | #if defined(__uClinux__) | 121 | #if defined(__uClinux__) |
122 | vfork_daemon_rexec(0, 1, argc, argv, "-n"); | 122 | vfork_daemon_rexec(0, 1, argc, argv, "-n"); |
123 | #else /* __uClinux__ */ | 123 | #else /* __uClinux__ */ |
124 | if (daemon(0, 1) < 0) | 124 | bb_xdaemon(0, 1); |
125 | bb_perror_msg_and_die("daemon"); | ||
126 | #endif /* __uClinux__ */ | 125 | #endif /* __uClinux__ */ |
127 | } | 126 | } |
128 | doKlogd(console_log_level); | 127 | doKlogd(console_log_level); |
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index b43c72d66..0fcbb48bc 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -673,8 +673,7 @@ int syslogd_main(int argc, char **argv) | |||
673 | #if defined(__uClinux__) | 673 | #if defined(__uClinux__) |
674 | vfork_daemon_rexec(0, 1, argc, argv, "-n"); | 674 | vfork_daemon_rexec(0, 1, argc, argv, "-n"); |
675 | #else /* __uClinux__ */ | 675 | #else /* __uClinux__ */ |
676 | if(daemon(0, 1) < 0) | 676 | bb_xdaemon(0, 1); |
677 | bb_perror_msg_and_die("daemon"); | ||
678 | #endif /* __uClinux__ */ | 677 | #endif /* __uClinux__ */ |
679 | } | 678 | } |
680 | doSyslogd(); | 679 | doSyslogd(); |