diff options
author | Denis Vlasenko | 2008-07-01 10:00:46 +0000 |
---|---|---|
committer | Denis Vlasenko | 2008-07-01 10:00:46 +0000 |
commit | 7987a1844b2fdf2e8086d1e723fbcfab20defb96 (patch) | |
tree | fdee7d81d53804f1446eb11edf4e879676065ef0 | |
parent | 3bb2bbd68419ce4e777a89bf43ea7e5781dd787f (diff) | |
download | busybox-7987a1844b2fdf2e8086d1e723fbcfab20defb96.zip busybox-7987a1844b2fdf2e8086d1e723fbcfab20defb96.tar.gz |
ssd: do not stat -x EXECUTABLE, it is not needed anymore
ssd: use PATH
ssd: fix -a without -x case
ssd: fix help text
ssd: CLOSE_EXTRA_FDS in MMU case too
ssd: add testsuite
-rw-r--r-- | debianutils/start_stop_daemon.c | 26 | ||||
-rw-r--r-- | include/usage.h | 4 | ||||
-rwxr-xr-x | testsuite/start-stop-daemon.tests | 19 |
3 files changed, 37 insertions, 12 deletions
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c index 86ec710..e082b5c 100644 --- a/debianutils/start_stop_daemon.c +++ b/debianutils/start_stop_daemon.c @@ -326,7 +326,9 @@ int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv) char *signame; char *startas; char *chuid; +#ifdef OLDER_VERSION_OF_X struct stat execstat; +#endif #if ENABLE_FEATURE_START_STOP_DAEMON_FANCY // char *retry_arg = NULL; // int retries = -1; @@ -361,6 +363,8 @@ int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv) if (!(opt & OPT_a)) startas = execname; + if (!execname) /* in case -a is given and -x is not */ + execname = startas; // USE_FEATURE_START_STOP_DAEMON_FANCY( // if (retry_arg) @@ -374,7 +378,8 @@ int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv) if (errno) user_id = xuname2uid(userspec); } - do_procinit(); /* Both start and stop needs to know current processes */ + /* Both start and stop need to know current processes */ + do_procinit(); if (opt & CTX_STOP) { int i = do_stop(); @@ -383,17 +388,21 @@ int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv) if (found) { if (!QUIET) - printf("%s already running\n%d\n", execname, found->pid); + printf("%s is already running\n%u\n", execname, (unsigned)found->pid); return !(opt & OPT_OKNODO); } +#ifdef OLDER_VERSION_OF_X if (execname) xstat(execname, &execstat); +#endif *--argv = startas; if (opt & OPT_BACKGROUND) { #if BB_MMU - bb_daemonize(0); + bb_daemonize(DAEMON_DEVNULL_STDIO + DAEMON_CLOSE_EXTRA_FDS); + /* DAEMON_DEVNULL_STDIO is superfluous - + * it's always done by bb_daemonize() */ #else pid_t pid = vfork(); if (pid < 0) /* error */ @@ -404,19 +413,18 @@ int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv) * so "return 0" may do bad things */ _exit(EXIT_SUCCESS); } - /* child */ + /* Child */ setsid(); /* detach from controlling tty */ /* Redirect stdio to /dev/null, close extra FDs. * We do not actually daemonize because of DAEMON_ONLY_SANITIZE */ - bb_daemonize_or_rexec( - DAEMON_DEVNULL_STDIO - + DAEMON_CLOSE_EXTRA_FDS + bb_daemonize_or_rexec(DAEMON_DEVNULL_STDIO + DAEMON_CLOSE_EXTRA_FDS + DAEMON_ONLY_SANITIZE, NULL /* argv, unused */ ); #endif } if (opt & OPT_MAKEPID) { - /* user wants _us_ to make the pidfile */ + /* User wants _us_ to make the pidfile */ write_pidfile(pidfile); } if (opt & OPT_c) { @@ -434,6 +442,6 @@ int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv) } } #endif - execv(startas, argv); + execvp(startas, argv); bb_perror_msg_and_die("cannot start %s", startas); } diff --git a/include/usage.h b/include/usage.h index d7bc018..f9a993a 100644 --- a/include/usage.h +++ b/include/usage.h @@ -3638,9 +3638,7 @@ "$ cat TODO | split -a 2 -l 2 TODO_\n" #define start_stop_daemon_trivial_usage \ - "[OPTIONS] [" \ - USE_GETOPT_LONG("--start|--stop") SKIP_GETOPT_LONG("-S|-K") \ - "] ... [-- arguments...]" + "[OPTIONS] [-S|-K] ... [-- arguments...]" #define start_stop_daemon_full_usage "\n\n" \ "Search for matching processes, and then\n" \ "-S: stop all matching processes.\n" \ diff --git a/testsuite/start-stop-daemon.tests b/testsuite/start-stop-daemon.tests new file mode 100755 index 0000000..ba77cde --- /dev/null +++ b/testsuite/start-stop-daemon.tests @@ -0,0 +1,19 @@ +#!/bin/sh +# Copyright 2008 by Denys Vlasenko +# Licensed under GPL v2, see file LICENSE for details. + +. testing.sh + +# testing "test name" "cmd" "expected result" "file input" "stdin" + +testing "start-stop-daemon -x without -a" \ + 'start-stop-daemon -S -x true 2>&1; echo $?' \ + "0\n" \ + "" "" + +testing "start-stop-daemon -a without -x" \ + 'start-stop-daemon -S -a false 2>&1; echo $?' \ + "1\n" \ + "" "" + +exit $FAILCOUNT |