Ver Fonte

Getting "Unrecognized option" if parameters after `-a` contain dashes

If the command ended in something like `-a --foo --bar baz`,
getopt_long would complain about `--bar` but check_nrpe would pass
along all the arguments anyway. The check for `-a` swallowed the
`--foo`, but the `--bar` confused it because the loop check after
the call to getopt_long for `if (argindex > 0)` instead of before.
John C. Frickson há 9 anos atrás
pai
commit
bbbeabfb5e
1 ficheiros alterados com 3 adições e 2 exclusões
  1. 3 2
      src/check_nrpe.c

+ 3 - 2
src/check_nrpe.c

@@ -225,12 +225,14 @@ int process_arguments(int argc, char **argv, int from_config_file)
 	snprintf(optchars, MAX_INPUT_BUFFER, "H:f:b:c:a:t:p:S:L:C:K:A:d:s:P:246hlnuV");
 	snprintf(optchars, MAX_INPUT_BUFFER, "H:f:b:c:a:t:p:S:L:C:K:A:d:s:P:246hlnuV");
 
 
 	while (1) {
 	while (1) {
+		if (argindex > 0)
+			break;
 #ifdef HAVE_GETOPT_LONG
 #ifdef HAVE_GETOPT_LONG
 		c = getopt_long(argc, argv, optchars, long_options, &option_index);
 		c = getopt_long(argc, argv, optchars, long_options, &option_index);
 #else
 #else
 		c = getopt(argc, argv, optchars);
 		c = getopt(argc, argv, optchars);
 #endif
 #endif
-		if (c == -1 || c == EOF || argindex > 0)
+		if (c == -1 || c == EOF)
 			break;
 			break;
 
 
 		/* process all arguments */
 		/* process all arguments */
@@ -476,7 +478,6 @@ int process_arguments(int argc, char **argv, int from_config_file)
 			query[sizeof(query) - 1] = '\x0';
 			query[sizeof(query) - 1] = '\x0';
 		}
 		}
 	}
 	}
-	printf("Query: |%s|\n", query);
 	if (!from_config_file && config_file != NULL) {
 	if (!from_config_file && config_file != NULL) {
 		if ((rc = read_config_file(config_file)) != OK)
 		if ((rc = read_config_file(config_file)) != OK)
 			return rc;
 			return rc;