]> granicus.if.org Git - psmisc/commitdiff
killall: ignore -n 0
authorCraig Small <csmall@enc.com.au>
Mon, 10 Sep 2018 12:41:45 +0000 (22:41 +1000)
committerCraig Small <csmall@enc.com.au>
Mon, 10 Sep 2018 12:41:45 +0000 (22:41 +1000)
While all namespaces are used by default, this means if someone used the
temporary -n 0 option in killall they will now get an error.

We just silently ignore it

References:
 commit 38829585c4f5b67c8c2a8cbdf86761a72ace43f6
 psmisc/psmisc#15

ChangeLog
src/killall.c

index 903503b44a79ae10b4f4e0014d2a1394746d69b8..350d1ec4c4f6a2a88cae93dbcbae58a9c63f43dc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,7 @@ Changes in 23.2
        * killall: look at all namespaces by default
        * killall: Fix -INT option parsing #11
        * killall: change to getopt_long without _only #12
+       * killall: ignore -n 0 #15
        * peekfd: Attach to all threads option !15
        * pslog: Define PATH_MAX if required Debian:#905797
 
index 7f982a1a2002f438483618bec76d895203fbeb3b..64c406abe510c9152ebdee33cd0ce353cea17383 100644 (file)
@@ -859,7 +859,7 @@ main (int argc, char **argv)
 #ifdef WITH_SELINUX
     while ( (optc = getopt_long(argc,argv,"egy:o:ilqrs:u:vwZ:VIn:",options,NULL)) != -1) {
 #else
-        while ( (optc = getopt_long(argc,argv,"egy:o:ilqrs:u:vwVIn:",options,NULL)) != -1) {
+        while ( (optc = getopt_long_only(argc,argv,"egy:o:ilqrs:u:vwVIn:",options,NULL)) != -1) {
 #endif
             switch (optc) {
             case 'e':
@@ -925,10 +925,15 @@ main (int argc, char **argv)
                 }
                 sig_num = get_signal (argv[optind]+1, "killall");
                 break;
-            case 'n':
-                opt_ns_pid = atoi(optarg);
-                if (opt_ns_pid == 0)
+            case 'n': {
+                long num;
+                char *end = NULL;
+                errno = 0;
+                num = strtol(optarg, &end, 10);
+                if (errno != 0 || optarg == end || end == NULL)
                     usage(_("Invalid namespace PID"));
+                opt_ns_pid = (pid_t) num;
+            }
                 break;
 #ifdef WITH_SELINUX
             case 'Z':