From 18c08390da033a44f977e44a32be079d85bf1ef9 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Wed, 7 Mar 2012 12:49:09 +0100 Subject: [PATCH] sysctl: fix argument parsing regression 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 Signed-off-by: Jim Warner Signed-off-by: Sami Kerola --- sysctl.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/sysctl.c b/sysctl.c index a2fa211e..e3619700 100644 --- 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; } -- 2.40.0