From: Vincent Bernat Date: Sat, 8 Aug 2015 17:01:17 +0000 (+0200) Subject: client: parse options only once X-Git-Tag: 0.7.17~20 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2b00cbf9d548c8b53735c3dbbf72715c381bf32f;p=thirdparty%2Flldpd.git client: parse options only once getopt() will parse them in order. If a user specifies `-d` after `-c`, they will be ignored but this seems like a corner case. --- diff --git a/src/client/lldpcli.c b/src/client/lldpcli.c index dc22da6f..a0b1d7a4 100644 --- a/src/client/lldpcli.c +++ b/src/client/lldpcli.c @@ -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);