More strict options handling
authorAleksei Vereshchagin <avereschagin@dev.rtsoft.ru>
Tue, 4 Sep 2018 19:45:29 +0000 (22:45 +0300)
committerAleksei Vereshchagin <avereschagin@dev.rtsoft.ru>
Mon, 10 Sep 2018 14:00:10 +0000 (17:00 +0300)
profctl.c

index 5ddeb0153991b8c0cf35a1abba159803e0b74622..352cd764c829b637319393949feedf6fa2ba3d95 100644 (file)
--- 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;