From 87094da7cdad1d9ad4a09ed765ba70247691502d Mon Sep 17 00:00:00 2001 From: Aleksei Vereshchagin Date: Tue, 4 Sep 2018 22:45:29 +0300 Subject: [PATCH] More strict options handling --- profctl.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/profctl.c b/profctl.c index 5ddeb01..352cd76 100644 --- a/profctl.c +++ b/profctl.c @@ -209,18 +209,8 @@ static int process_option(int argc, char **argv) { int option_index; - switch (getopt_long(argc, argv, "-a:p:ve:o:it:wc:d:s:", + switch (getopt_long(argc, argv, "+a:p:ve:o:it:wc:d:s:", long_options, &option_index)) { - case 1: - if (appid == NULL) { - appid = optarg; - } else if (pname == NULL) { - pname = optarg; - } else { - log_error("extra argument %s", optarg); - exit(1); - } - break; case 'a': CheckValue(&appid, "appid"); break; case 'p': CheckValue(&pname, "pipe name"); break; case 'e': CheckValue(&ename, "exe name"); break; @@ -232,7 +222,13 @@ static int process_option(int argc, char **argv) case 'c': controlPort = atoi(optarg); break; case 'd': dataPort = atoi(optarg); break; case 's': statPort = atoi(optarg); break; + case '?': exit(1); default: + if (optind != argc) + { + log_error("extra argument %s", argv[optind]); + exit(1); + } return -1; } return 0; -- 2.7.4