]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
client: parse options only once
authorVincent Bernat <vincent@bernat.im>
Sat, 8 Aug 2015 17:01:17 +0000 (19:01 +0200)
committerVincent Bernat <vincent@bernat.im>
Sat, 8 Aug 2015 17:01:17 +0000 (19:01 +0200)
getopt() will parse them in order. If a user specifies `-d` after `-c`,
they will be ignored but this seems like a corner case.

src/client/lldpcli.c

index dc22da6f32b1576cdde37d248a9514e44593a7d9..a0b1d7a4866f2e4352f6a8e30d1901c518ec21eb 100644 (file)
@@ -442,22 +442,12 @@ main(int argc, char *argv[])
 
        signal(SIGHUP, SIG_IGN);
 
-       /* Initialize logging */
-       while ((ch = getopt(argc, argv, options)) != -1) {
-               switch (ch) {
-               case 'd': debug++; break;
-               case 's': debug--; break;
-               }
-       }
-       log_init(debug, __progname);
-       lldpctl_log_level(debug);
-
        /* Get and parse command line options */
        optind = 1;
        while ((ch = getopt(argc, argv, options)) != -1) {
                switch (ch) {
-               case 'd': break;
-               case 's': break;
+               case 'd': debug++; break;
+               case 's': debug--; break;
                case 'h':
                        usage();
                        break;
@@ -472,7 +462,11 @@ main(int argc, char *argv[])
                        fmt = optarg;
                        break;
                case 'c':
-                       gotinputs = 1;
+                       if (!gotinputs) {
+                               log_init(debug, __progname);
+                               lldpctl_log_level(debug);
+                               gotinputs = 1;
+                       }
                        input_append(optarg, &inputs, 1);
                        break;
                default:
@@ -480,6 +474,11 @@ main(int argc, char *argv[])
                }
        }
 
+       if (!gotinputs) {
+               log_init(debug, __progname);
+               lldpctl_log_level(debug);
+       }
+
        /* Disable SIGPIPE */
        signal(SIGPIPE, SIG_IGN);