Fix repmgrd's command line help option parsing

As in commit d0c05e6f46, properly distinguish between
the command line option -? and getopt's unknown option marker '?'
This commit is contained in:
Ian Barwick
2016-08-08 21:17:56 +09:00
parent cb78802027
commit 6a198401db

View File

@@ -128,7 +128,7 @@ main(int argc, char **argv)
{"monitoring-history", no_argument, NULL, 'm'},
{"daemonize", no_argument, NULL, 'd'},
{"pid-file", required_argument, NULL, 'p'},
{"help", no_argument, NULL, '?'},
{"help", no_argument, NULL, OPT_HELP},
{"version", no_argument, NULL, 'V'},
{NULL, 0, NULL, 0}
};
@@ -162,6 +162,23 @@ main(int argc, char **argv)
{
switch (c)
{
case '?':
/* Actual help option given */
if (strcmp(argv[optind - 1], "-?") == 0)
{
help();
exit(SUCCESS);
}
/* unknown option reported by getopt */
else
goto unknown_option;
break;
case OPT_HELP:
help();
exit(SUCCESS);
case 'V':
printf("%s %s (PostgreSQL %s)\n", progname(), REPMGR_VERSION, PG_VERSION);
exit(SUCCESS);
case 'f':
config_file = optarg;
break;
@@ -177,13 +194,9 @@ main(int argc, char **argv)
case 'p':
pid_file = optarg;
break;
case '?':
help();
exit(SUCCESS);
case 'V':
printf("%s %s (PostgreSQL %s)\n", progname(), REPMGR_VERSION, PG_VERSION);
exit(SUCCESS);
default:
unknown_option:
usage();
exit(ERR_BAD_CONFIG);
}