]> granicus.if.org Git - procps-ng/commitdiff
sysctl: fix argument parsing regression
authorJim Warner <james.warner@comcast.net>
Wed, 7 Mar 2012 11:49:09 +0000 (12:49 +0100)
committerCraig Small <csmall@enc.com.au>
Wed, 7 Mar 2012 21:40:02 +0000 (08:40 +1100)
Any key=value pair following the first one are dropped after
commit 81df8e26300b35968e3702decc02e9413d5389fc, due to changing
from the while loop to using getopt.

Broken behavior:
  sysctl net.ipv6.conf.tun0.optimistic_dad net.ipv6.conf.tun0.mc_forwarding
  net.ipv6.conf.tun0.optimistic_dad = 0

Good behavior:
  sysctl net.ipv6.conf.tun0.optimistic_dad net.ipv6.conf.tun0.mc_forwarding
  net.ipv6.conf.tun0.optimistic_dad = 0
  net.ipv6.conf.tun0.mc_forwarding = 0

Reference: http://www.freelists.org/post/procps/BUG-Commit-81df8e2-allows-only-one-keyvalue-arg
Reported-By: Sven Ulland <sveniu@opera.com>
Signed-off-by: Jim Warner <james.warner@comcast.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
sysctl.c

index a2fa211e9ae62738dcb191fd016ac0e46f20e217..e36197006455a28da18374ded338e23ed67cee29 100644 (file)
--- a/sysctl.c
+++ b/sysctl.c
@@ -687,7 +687,7 @@ int main(int argc, char *argv[])
 
        while ((c =
                getopt_long(argc, argv, "bneNwfp::qoxaAXr:Vdh", longopts,
-                           NULL)) != -1)
+                           NULL)) != -1) {
                switch (c) {
                case 'b':
                        /* This is "binary" format, which means more for BSD. */
@@ -748,6 +748,8 @@ int main(int argc, char *argv[])
                default:
                        Usage(stderr);
                }
+       }
+
        if (DisplayAllOpt)
                return DisplayAll(PROC_PATH);
        if (preloadfileOpt)
@@ -765,10 +767,11 @@ int main(int argc, char *argv[])
                                      "Try `%s --help' for more information."),
                      program_invocation_short_name);
 
-       if (WriteMode || index(*argv, '='))
-               ReturnCode = WriteSetting(*argv);
-       else
-               ReturnCode = ReadSetting(*argv);
-
+       for ( ; *argv; argv++) {
+               if (WriteMode || index(*argv, '='))
+                       ReturnCode += WriteSetting(*argv);
+               else
+                       ReturnCode += ReadSetting(*argv);
+       }
        return ReturnCode;
 }