From: Alexander Vickberg Date: Sat, 27 Apr 2019 13:42:41 +0000 (+0200) Subject: start-stop-daemon: Fix -x is not required for -K X-Git-Tag: 1_31_0~83 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=100fa20c68564311cef8f625bcb1b423e96c97d6;p=oweals%2Fbusybox.git start-stop-daemon: Fix -x is not required for -K Commit 088fec36fedff2cd50437c95b7fb430abf8d303c made -x required for all. However it isn't for -K. function old new delta start_stop_daemon_main 1084 1105 +21 packed_usage 33343 33326 -17 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 21/-17) Total: 4 bytes Signed-off-by: Alexander Vickberg Signed-off-by: Denys Vlasenko --- diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c index 3a4c1044a..72642ae74 100644 --- a/debianutils/start_stop_daemon.c +++ b/debianutils/start_stop_daemon.c @@ -94,7 +94,7 @@ Misc options: //usage: "\n -n NAME Match processes with NAME" //usage: "\n in comm field in /proc/PID/stat" //usage: "\n -x EXECUTABLE Match processes with this command" -//usage: "\n command in /proc/PID/cmdline" +//usage: "\n in /proc/PID/cmdline" //usage: "\n -p FILE Match a process with PID from FILE" //usage: "\n All specified conditions must match" //usage: "\n-S only:" @@ -452,31 +452,34 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv) // "start-stop-daemon -S -a sleep -- 5" // NB: -n option does _not_ behave in this way: this will try to execute "5": // "start-stop-daemon -S -n sleep -- 5" - if (!execname) { /* -x is not given */ - execname = startas; - if (!execname) { /* neither -x nor -a is given */ - execname = argv[0]; - if (!execname) - bb_show_usage(); - argv++; + if (opt & CTX_START) { + if (!execname) { /* -x is not given */ + execname = startas; + if (!execname) { /* neither -x nor -a is given */ + execname = argv[0]; + if (!execname) + bb_show_usage(); + argv++; + } } + if (!startas) /* -a is not given: use -x EXECUTABLE or argv[0] */ + startas = execname; + *--argv = startas; + } + if (execname) { + G.execname_sizeof = strlen(execname) + 1; + G.execname_cmpbuf = xmalloc(G.execname_sizeof + 1); } - if (!startas) /* -a is not given: use -x EXECUTABLE or argv[0] */ - startas = execname; - *--argv = startas; - G.execname_sizeof = strlen(execname) + 1; - G.execname_cmpbuf = xmalloc(G.execname_sizeof + 1); - // IF_FEATURE_START_STOP_DAEMON_FANCY( // if (retry_arg) // retries = xatoi_positive(retry_arg); // ) - if (userspec) { user_id = bb_strtou(userspec, NULL, 10); if (errno) user_id = xuname2uid(userspec); } + /* Both start and stop need to know current processes */ do_procinit(); @@ -485,6 +488,8 @@ int start_stop_daemon_main(int argc UNUSED_PARAM, char **argv) return (opt & OPT_OKNODO) ? 0 : (i <= 0); } + /* else: CTX_START (-S). execname can't be NULL. */ + if (G.found_procs) { if (!QUIET) printf("%s is already running\n", execname);