diff options
author | Eric Andersen | 2002-01-26 09:04:45 +0000 |
---|---|---|
committer | Eric Andersen | 2002-01-26 09:04:45 +0000 |
commit | 53a2299230976b93d3bbe81ad92dad8c23d0b271 (patch) | |
tree | 9999687b999f7bc0647fae38ee0ca20c066d53de /init | |
parent | 467a18b1d94dbcdc9f750e52d09f6579037fbff5 (diff) | |
download | busybox-53a2299230976b93d3bbe81ad92dad8c23d0b271.zip busybox-53a2299230976b93d3bbe81ad92dad8c23d0b271.tar.gz |
Patch from Russ Dill <Russ.Dill@asu.edu>. From the
start-stop-daemon man page:
-b|--background
Typically used with programs that don't detach on their own.
This option will force start-stop-daemon to fork before starting
the process, and force it into the background. WARNING:
start-stop-daemon cannot check the exit status if the process
fails to execute for any reason. This is a last resort, and is
only meant for programs that either make no sense forking on
their own, or where it's not feasible to add the code for it to
do this itself.
This is usefull for applets like watchdog
Diffstat (limited to 'init')
-rw-r--r-- | init/start_stop_daemon.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/init/start_stop_daemon.c b/init/start_stop_daemon.c index c6b7043..ed4503c 100644 --- a/init/start_stop_daemon.c +++ b/init/start_stop_daemon.c @@ -22,6 +22,7 @@ static int start = 0; static int stop = 0; +static int fork_before_exec = 0; static int signal_nr = 15; static int user_id = -1; static const char *userspec = NULL; @@ -55,7 +56,7 @@ parse_options(int argc, char * const *argv) int c; for (;;) { - c = getopt (argc, argv, "a:n:s:u:x:KS"); + c = getopt (argc, argv, "a:n:s:u:x:KSb"); if (c == EOF) break; switch (c) { @@ -81,6 +82,9 @@ parse_options(int argc, char * const *argv) case 'x': execname = optarg; break; + case 'b': + fork_before_exec = 1; + break; default: show_usage(); } @@ -255,6 +259,11 @@ start_stop_daemon_main(int argc, char **argv) return EXIT_SUCCESS; } *--argv = startas; + if (fork_before_exec) { + if (daemon(0, 0) == -1) + perror_msg_and_die ("unable to fork"); + } + setsid(); execv(startas, argv); perror_msg_and_die ("unable to start %s", startas); } |