aboutsummaryrefslogtreecommitdiff
path: root/debianutils
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2002-01-26 09:04:45 +0000
committerEric Andersen <andersen@codepoet.org>2002-01-26 09:04:45 +0000
commit53a2299230976b93d3bbe81ad92dad8c23d0b271 (patch)
tree9999687b999f7bc0647fae38ee0ca20c066d53de /debianutils
parent467a18b1d94dbcdc9f750e52d09f6579037fbff5 (diff)
downloadbusybox-w32-53a2299230976b93d3bbe81ad92dad8c23d0b271.tar.gz
busybox-w32-53a2299230976b93d3bbe81ad92dad8c23d0b271.tar.bz2
busybox-w32-53a2299230976b93d3bbe81ad92dad8c23d0b271.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
Diffstat (limited to 'debianutils')
-rw-r--r--debianutils/start_stop_daemon.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c
index c6b704329..ed4503caf 100644
--- a/debianutils/start_stop_daemon.c
+++ b/debianutils/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}