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
This commit is contained in:
parent
467a18b1d9
commit
53a2299230
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user