aboutsummaryrefslogtreecommitdiff
path: root/init
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2002-01-26 09:04:45 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2002-01-26 09:04:45 +0000
commit8832d72e12ae950c04bc0f429ec8829c47c55582 (patch)
tree9999687b999f7bc0647fae38ee0ca20c066d53de /init
parent7026c59b5ef1767bfcea65060fca615b00a4b283 (diff)
downloadbusybox-w32-8832d72e12ae950c04bc0f429ec8829c47c55582.tar.gz
busybox-w32-8832d72e12ae950c04bc0f429ec8829c47c55582.tar.bz2
busybox-w32-8832d72e12ae950c04bc0f429ec8829c47c55582.zip
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 git-svn-id: svn://busybox.net/trunk/busybox@4112 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'init')
-rw-r--r--init/start_stop_daemon.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/init/start_stop_daemon.c b/init/start_stop_daemon.c
index c6b704329..ed4503caf 100644
--- a/init/start_stop_daemon.c
+++ b/init/start_stop_daemon.c
@@ -22,6 +22,7 @@
22 22
23static int start = 0; 23static int start = 0;
24static int stop = 0; 24static int stop = 0;
25static int fork_before_exec = 0;
25static int signal_nr = 15; 26static int signal_nr = 15;
26static int user_id = -1; 27static int user_id = -1;
27static const char *userspec = NULL; 28static const char *userspec = NULL;
@@ -55,7 +56,7 @@ parse_options(int argc, char * const *argv)
55 int c; 56 int c;
56 57
57 for (;;) { 58 for (;;) {
58 c = getopt (argc, argv, "a:n:s:u:x:KS"); 59 c = getopt (argc, argv, "a:n:s:u:x:KSb");
59 if (c == EOF) 60 if (c == EOF)
60 break; 61 break;
61 switch (c) { 62 switch (c) {
@@ -81,6 +82,9 @@ parse_options(int argc, char * const *argv)
81 case 'x': 82 case 'x':
82 execname = optarg; 83 execname = optarg;
83 break; 84 break;
85 case 'b':
86 fork_before_exec = 1;
87 break;
84 default: 88 default:
85 show_usage(); 89 show_usage();
86 } 90 }
@@ -255,6 +259,11 @@ start_stop_daemon_main(int argc, char **argv)
255 return EXIT_SUCCESS; 259 return EXIT_SUCCESS;
256 } 260 }
257 *--argv = startas; 261 *--argv = startas;
262 if (fork_before_exec) {
263 if (daemon(0, 0) == -1)
264 perror_msg_and_die ("unable to fork");
265 }
266 setsid();
258 execv(startas, argv); 267 execv(startas, argv);
259 perror_msg_and_die ("unable to start %s", startas); 268 perror_msg_and_die ("unable to start %s", startas);
260} 269}