[PATCH] sysctl: option -p does not need to support optional argume=

  • From: Sami Kerola <kerolasa@xxxxxx>
  • Date: Fri, 4 May 2012 17:19:19 +0200

The optional argument syntax is simply causing confusion, and is
not POSIX compliant way of using getopt(3).

Reference: //www.freelists.org/post/procps/PATCH-v2-sysctl-restore-old=
-p-handling,9
Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 sysctl.c |   21 +++++++--------------
 1 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/sysctl.c b/sysctl.c
index cfe1398..ce3338e 100644
--- a/sysctl.c
+++ b/sysctl.c
@@ -113,7 +113,7 @@ static void __attribute__ ((__noreturn__))
                "  -e, --ignore         ignore unknown variables errors\n"
                "  -N, --names          print variable names without values\n"
                "  -n, --values         print only values of a variables\n"
-               "  -p, --load[=3D<file>]  read values from file\n"
+               "  -p, --load           read values from file\n"
                "  -f                   alias of -p\n"
                "      --system         read values from all system 
directories\n"
                "  -r, --pattern <expression>\n"
@@ -666,7 +666,7 @@ int main(int argc, char *argv[])
                {"ignore", no_argument, NULL, 'e'},
                {"names", no_argument, NULL, 'N'},
                {"values", no_argument, NULL, 'n'},
-               {"load", optional_argument, NULL, 'p'},
+               {"load", no_argument, NULL, 'p'},
                {"quiet", no_argument, NULL, 'q'},
                {"write", no_argument, NULL, 'w'},
                {"system", no_argument, NULL, SYSTEM_OPTION},
@@ -692,7 +692,7 @@ int main(int argc, char *argv[])
                Usage(stderr);

        while ((c =3D
-               getopt_long(argc, argv, "bneNwfp::qoxaAXr:Vdh", longopts,
+               getopt_long(argc, argv, "bneNwfpqoxaAXr:Vdh", longopts,
                            NULL)) !=3D -1) {
                switch (c) {
                case 'b':
@@ -720,8 +720,6 @@ int main(int argc, char *argv[])
                case 'f':       /* the NetBSD way */
                case 'p':
                        preloadfileOpt =3D true;
-                       if (optarg)
-                               preloadfile =3D optarg;
                        break;
                case 'q':
                        Quiet =3D true;
@@ -764,17 +762,12 @@ int main(int argc, char *argv[])

        if (preloadfileOpt) {
                int ret =3D EXIT_SUCCESS, i;
-               if (!preloadfile) {
-                       if (!argc) {
-                               ret !=3D Preload(DEFAULT_PRELOAD);
-                       }
+               if (argc =3D=3D 0) {
+                       ret =3D Preload(DEFAULT_PRELOAD);
                } else {
-                       /* This happens when -pfile option is
-                        * used without space. */
-                       Preload(preloadfile);
+                       for (i =3D 0; i < argc; i++)
+                               ret |=3D Preload(argv[i]);
                }
-               for (i =3D 0; i < argc; i++)
-                       Preload(argv[i]);
                return ret;
        }

--=20
1.7.5.4

Also available in my git branch 'mike'.

https://gitorious.org/~kerolasa/procps/sami-procps-ng/commit/77214bbac8df3c=
69dd88ffd1e78b3b0a64ece3ab

--=20
=A0=A0 Sami Kerola
=A0=A0 http://www.iki.fi/kerolasa/

Other related posts:

  • » [PATCH] sysctl: option -p does not need to support optional argume= - Sami Kerola