From 2b00cbf9d548c8b53735c3dbbf72715c381bf32f Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sat, 8 Aug 2015 19:01:17 +0200 Subject: [PATCH] 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. --- src/client/lldpcli.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) 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); -- 2.39.5