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
This commit is contained in:
Denis Vlasenko 2008-07-01 10:00:46 +00:00
parent 3bb2bbd684
commit 7987a1844b
3 changed files with 37 additions and 12 deletions

View File

@ -326,7 +326,9 @@ int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv)
char *signame; char *signame;
char *startas; char *startas;
char *chuid; char *chuid;
#ifdef OLDER_VERSION_OF_X
struct stat execstat; struct stat execstat;
#endif
#if ENABLE_FEATURE_START_STOP_DAEMON_FANCY #if ENABLE_FEATURE_START_STOP_DAEMON_FANCY
// char *retry_arg = NULL; // char *retry_arg = NULL;
// int retries = -1; // int retries = -1;
@ -361,6 +363,8 @@ int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv)
if (!(opt & OPT_a)) if (!(opt & OPT_a))
startas = execname; startas = execname;
if (!execname) /* in case -a is given and -x is not */
execname = startas;
// USE_FEATURE_START_STOP_DAEMON_FANCY( // USE_FEATURE_START_STOP_DAEMON_FANCY(
// if (retry_arg) // if (retry_arg)
@ -374,7 +378,8 @@ int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv)
if (errno) if (errno)
user_id = xuname2uid(userspec); 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) { if (opt & CTX_STOP) {
int i = do_stop(); int i = do_stop();
@ -383,17 +388,21 @@ int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv)
if (found) { if (found) {
if (!QUIET) 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); return !(opt & OPT_OKNODO);
} }
#ifdef OLDER_VERSION_OF_X
if (execname) if (execname)
xstat(execname, &execstat); xstat(execname, &execstat);
#endif
*--argv = startas; *--argv = startas;
if (opt & OPT_BACKGROUND) { if (opt & OPT_BACKGROUND) {
#if BB_MMU #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 #else
pid_t pid = vfork(); pid_t pid = vfork();
if (pid < 0) /* error */ 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 */ * so "return 0" may do bad things */
_exit(EXIT_SUCCESS); _exit(EXIT_SUCCESS);
} }
/* child */ /* Child */
setsid(); /* detach from controlling tty */ setsid(); /* detach from controlling tty */
/* Redirect stdio to /dev/null, close extra FDs. /* Redirect stdio to /dev/null, close extra FDs.
* We do not actually daemonize because of DAEMON_ONLY_SANITIZE */ * We do not actually daemonize because of DAEMON_ONLY_SANITIZE */
bb_daemonize_or_rexec( bb_daemonize_or_rexec(DAEMON_DEVNULL_STDIO
DAEMON_DEVNULL_STDIO DAEMON_CLOSE_EXTRA_FDS
+ DAEMON_CLOSE_EXTRA_FDS
+ DAEMON_ONLY_SANITIZE, + DAEMON_ONLY_SANITIZE,
NULL /* argv, unused */ ); NULL /* argv, unused */ );
#endif #endif
} }
if (opt & OPT_MAKEPID) { if (opt & OPT_MAKEPID) {
/* user wants _us_ to make the pidfile */ /* User wants _us_ to make the pidfile */
write_pidfile(pidfile); write_pidfile(pidfile);
} }
if (opt & OPT_c) { if (opt & OPT_c) {
@ -434,6 +442,6 @@ int start_stop_daemon_main(int argc ATTRIBUTE_UNUSED, char **argv)
} }
} }
#endif #endif
execv(startas, argv); execvp(startas, argv);
bb_perror_msg_and_die("cannot start %s", startas); bb_perror_msg_and_die("cannot start %s", startas);
} }

View File

@ -3638,9 +3638,7 @@
"$ cat TODO | split -a 2 -l 2 TODO_\n" "$ cat TODO | split -a 2 -l 2 TODO_\n"
#define start_stop_daemon_trivial_usage \ #define start_stop_daemon_trivial_usage \
"[OPTIONS] [" \ "[OPTIONS] [-S|-K] ... [-- arguments...]"
USE_GETOPT_LONG("--start|--stop") SKIP_GETOPT_LONG("-S|-K") \
"] ... [-- arguments...]"
#define start_stop_daemon_full_usage "\n\n" \ #define start_stop_daemon_full_usage "\n\n" \
"Search for matching processes, and then\n" \ "Search for matching processes, and then\n" \
"-S: stop all matching processes.\n" \ "-S: stop all matching processes.\n" \

View File

@ -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