sysctl: fix argument parsing regression

Any key=value pair following the first one are dropped after
commit 81df8e2630, 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>
This commit is contained in:
Jim Warner 2012-03-07 12:49:09 +01:00 committed by Craig Small
parent 87bb21b557
commit 18c08390da

View File

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