start-stop-daemon: Fix -x is not required for -K
authorAlexander Vickberg <wickbergster@gmail.com>
Sat, 27 Apr 2019 13:42:41 +0000 (15:42 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sat, 27 Apr 2019 13:43:43 +0000 (15:43 +0200)
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 <wickbergster@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
debianutils/start_stop_daemon.c

index 3a4c1044ab2ccc3a053b23a8d6929bfc1d474cbd..72642ae7410c4405a5ccdca15eed2b469af78bbf 100644 (file)
@@ -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);