aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-03-26 13:20:54 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-03-26 13:20:54 +0000
commit5a142025d372ae5dff7d7cf98f442edaafd1dc30 (patch)
tree19d222f7d7040945cf92e239055dfdd00b8656bc
parentbb7fcb4229fd5ff583039f26ca1c06340e3f09ea (diff)
downloadbusybox-5a142025d372ae5dff7d7cf98f442edaafd1dc30.tar.gz
move everything to new NOMMU helpers, except udhcp
-rw-r--r--debianutils/start_stop_daemon.c3
-rw-r--r--miscutils/crond.c64
-rw-r--r--miscutils/watchdog.c15
-rw-r--r--networking/dnsd.c7
-rw-r--r--networking/httpd.c2
-rw-r--r--networking/inetd.c28
-rw-r--r--networking/isrv_identd.c4
-rw-r--r--networking/telnetd.c2
-rw-r--r--networking/zcip.c3
-rw-r--r--sysklogd/klogd.c7
-rw-r--r--sysklogd/syslogd.c7
11 files changed, 40 insertions, 102 deletions
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c
index 1862f113d..60a78793e 100644
--- a/debianutils/start_stop_daemon.c
+++ b/debianutils/start_stop_daemon.c
@@ -299,8 +299,7 @@ int start_stop_daemon_main(int argc, char **argv)
}
*--argv = startas;
if (opt & OPT_BACKGROUND) {
- setsid();
- bb_daemonize();
+ bb_daemonize(0);
}
if (opt & OPT_MAKEPID) {
/* user wants _us_ to make the pidfile */
diff --git a/miscutils/crond.c b/miscutils/crond.c
index 1ab0038e0..9d511f960 100644
--- a/miscutils/crond.c
+++ b/miscutils/crond.c
@@ -136,75 +136,43 @@ int crond_main(int ac, char **av)
{
unsigned opt;
char *lopt, *Lopt, *copt;
+ USE_DEBUG_CROND_OPTION(char *dopt;)
-#if ENABLE_DEBUG_CROND_OPTION
- char *dopt;
-
- opt_complementary = "f-b:b-f:S-L:L-S:d-l";
-#else
- opt_complementary = "f-b:b-f:S-L:L-S";
-#endif
-
+ opt_complementary = "f-b:b-f:S-L:L-S" USE_DEBUG_CROND_OPTION(":d-l");
opterr = 0; /* disable getopt 'errors' message. */
- opt = getopt32(ac, av, "l:L:fbSc:"
-#if ENABLE_DEBUG_CROND_OPTION
- "d:"
-#endif
- , &lopt, &Lopt, &copt
-#if ENABLE_DEBUG_CROND_OPTION
- , &dopt
-#endif
- );
- if (opt & 1) {
+ opt = getopt32(ac, av, "l:L:fbSc:" USE_DEBUG_CROND_OPTION("d:"),
+ &lopt, &Lopt, &copt USE_DEBUG_CROND_OPTION(, &dopt));
+ if (opt & 1) /* -l */
LogLevel = xatou(lopt);
- }
- if (opt & 2) {
- if (*Lopt != 0) {
+ if (opt & 2) /* -L */
+ if (*Lopt)
LogFile = Lopt;
- }
- }
- if (opt & 32) {
- if (*copt != 0) {
+ if (opt & 32) /* -c */
+ if (*copt)
CDir = copt;
- }
- }
#if ENABLE_DEBUG_CROND_OPTION
- if (opt & 64) {
+ if (opt & 64) { /* -d */
DebugOpt = xatou(dopt);
LogLevel = 0;
}
#endif
- /*
- * change directory
- */
-
- xchdir(CDir);
- signal(SIGHUP, SIG_IGN); /* hmm.. but, if kill -HUP original
- * version - his died. ;(
- */
- /*
- * close stdin and stdout, stderr.
+ /* close stdin and stdout, stderr.
* close unused descriptors - don't need.
* optional detach from controlling terminal
*/
+ if (!(opt & 4))
+ bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, av);
- if (!(opt & 4)) {
-#ifdef BB_NOMMU
- if (!re_execed)
- vfork_daemon_rexec(1, 0, av);
-#else
- xdaemon(1, 0);
-#endif
- }
+ xchdir(CDir);
+ signal(SIGHUP, SIG_IGN); /* ? original crond dies on HUP... */
- (void) startlogger(); /* need if syslog mode selected */
+ startlogger(); /* need if syslog mode selected */
/*
* main loop - synchronize to 1 second after the minute, minimum sleep
* of 1 second.
*/
-
crondlog("\011%s " VERSION " dillon, started, log level %d\n",
applet_name, LogLevel);
diff --git a/miscutils/watchdog.c b/miscutils/watchdog.c
index e3d77d17e..28ae9bdb0 100644
--- a/miscutils/watchdog.c
+++ b/miscutils/watchdog.c
@@ -29,29 +29,21 @@ int watchdog_main(int argc, char **argv)
unsigned timer_duration = 30; /* Userspace timer duration, in seconds */
char *t_arg;
+ opt_complementary = "=1"; /* must have 1 argument */
opts = getopt32(argc, argv, "Ft:", &t_arg);
if (opts & OPT_TIMER)
timer_duration = xatou(t_arg);
- /* We're only interested in the watchdog device .. */
- if (optind < argc - 1 || argc == 1)
- bb_show_usage();
-
if (!(opts & OPT_FOREGROUND)) {
-#ifdef BB_NOMMU
- if (!re_execed)
- vfork_daemon_rexec(0, 1, argv);
-#else
- xdaemon(0, 1);
-#endif
+ bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
}
signal(SIGHUP, watchdog_shutdown);
signal(SIGINT, watchdog_shutdown);
/* Use known fd # - avoid needing global 'int fd' */
- dup2(xopen(argv[argc - 1], O_WRONLY), 3);
+ xmove_fd(xopen(argv[argc - 1], O_WRONLY), 3);
while (1) {
/*
@@ -63,6 +55,5 @@ int watchdog_main(int argc, char **argv)
}
watchdog_shutdown(0);
-
/* return EXIT_SUCCESS; */
}
diff --git a/networking/dnsd.c b/networking/dnsd.c
index c9c7b3a7c..8807bbedc 100644
--- a/networking/dnsd.c
+++ b/networking/dnsd.c
@@ -353,12 +353,7 @@ int dnsd_main(int argc, char **argv)
}
if (OPT_daemon) {
-#ifdef BB_NOMMU
- if (!re_execed)
- vfork_daemon_rexec(1, 0, argv);
-#else
- xdaemon(1, 0);
-#endif
+ bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv);
openlog(applet_name, LOG_PID, LOG_DAEMON);
logmode = LOGMODE_SYSLOG;
}
diff --git a/networking/httpd.c b/networking/httpd.c
index 72b03de79..b8d9b6b6f 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -2044,6 +2044,6 @@ int httpd_main(int argc, char *argv[])
return miniHttpd_inetd();
if (!(opt & OPT_FOREGROUND))
- xdaemon(1, 0); /* don't change current directory */
+ bb_daemonize(0); /* don't change current directory */
return miniHttpd(config->server_socket);
}
diff --git a/networking/inetd.c b/networking/inetd.c
index 83123463f..4faa4203a 100644
--- a/networking/inetd.c
+++ b/networking/inetd.c
@@ -1274,30 +1274,24 @@ int inetd_main(int argc, char *argv[])
LastArg = envp[-1] + strlen(envp[-1]);
#endif
- opt = getopt32(argc, argv, "R:f", &stoomany);
- if(opt & 1) {
- toomany = xatoi_u(stoomany);
- }
- argc -= optind;
- argv += optind;
-
uid = getuid();
if (uid != 0)
config_filename = NULL;
- if (argc > 0)
+
+ opt = getopt32(argc, argv, "R:f", &stoomany);
+ if (opt & 1)
+ toomany = xatoi_u(stoomany);
+ argv += optind;
+ argc -= optind;
+ if (argc)
config_filename = argv[0];
if (config_filename == NULL)
bb_error_msg_and_die("non-root must specify a config file");
-#ifdef BB_NOMMU
- if (!(opt & 2)) {
- if (!re_execed)
- vfork_daemon_rexec(0, 0, argv);
- }
- bb_sanitize_stdio();
-#else
- bb_sanitize_stdio_maybe_daemonize(!(opt & 2));
-#endif
+ if (!(opt & 2))
+ bb_daemonize_or_rexec(0, argv - optind);
+ else
+ bb_sanitize_stdio();
openlog(applet_name, LOG_PID | LOG_NOWAIT, LOG_DAEMON);
logmode = LOGMODE_SYSLOG;
diff --git a/networking/isrv_identd.c b/networking/isrv_identd.c
index f9ab0b2c0..c230c7ec3 100644
--- a/networking/isrv_identd.c
+++ b/networking/isrv_identd.c
@@ -112,7 +112,9 @@ int fakeidentd_main(int argc, char **argv)
bogouser = argv[optind];
/* Daemonize if no -f and no -i and no -w */
- bb_sanitize_stdio_maybe_daemonize(!(opt & OPT_fiw));
+ if (!(opt & OPT_fiw));
+ bb_daemonize_or_rexec(0, argv);
+
/* Where to log in inetd modes? "Classic" inetd
* probably has its stderr /dev/null'ed (we need log to syslog?),
* but daemontools-like utilities usually expect that children
diff --git a/networking/telnetd.c b/networking/telnetd.c
index ef9b1ac74..5c0463bab 100644
--- a/networking/telnetd.c
+++ b/networking/telnetd.c
@@ -415,7 +415,7 @@ int telnetd_main(int argc, char **argv)
master_fd = create_and_bind_stream_or_die(opt_bindaddr, portnbr);
xlisten(master_fd, 1);
if (!(opt & OPT_FOREGROUND))
- xdaemon(0, 0);
+ bb_daemonize(DAEMON_CHDIR_ROOT);
}
#else
sessions = make_new_session();
diff --git a/networking/zcip.c b/networking/zcip.c
index c50d5abaf..c0cf665dd 100644
--- a/networking/zcip.c
+++ b/networking/zcip.c
@@ -271,9 +271,8 @@ int zcip_main(int argc, char *argv[])
// daemonize now; don't delay system startup
if (!FOREGROUND) {
- /* bb_daemonize(); - bad, will close fd! */
//NOMMU
- xdaemon(0, 0);
+ bb_daemonize(DAEMON_CHDIR_ROOT);
bb_info_msg("start, interface %s", intf);
}
diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c
index fc0ed3037..62425394c 100644
--- a/sysklogd/klogd.c
+++ b/sysklogd/klogd.c
@@ -50,12 +50,7 @@ int klogd_main(int argc, char **argv)
}
if (!(option_mask32 & OPT_FOREGROUND)) {
-#ifdef BB_NOMMU
- if (!re_execed)
- vfork_daemon_rexec(0, 1, argv);
-#else
- bb_daemonize();
-#endif
+ bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
}
openlog("kernel", 0, LOG_KERN);
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index 437212372..51627bd82 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -642,12 +642,7 @@ int syslogd_main(int argc, char **argv)
}
if (!(option_mask32 & OPT_nofork)) {
-#ifdef BB_NOMMU
- if (!re_execed)
- vfork_daemon_rexec(0, 1, argv);
-#else
- bb_daemonize();
-#endif
+ bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
}
umask(0);
do_syslogd();