From af6f0fc2cf1250e51ae6420dbb4ceb9b5ad2e42c Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Mon, 8 Aug 2016 21:17:56 +0900 Subject: [PATCH] Fix repmgrd's command line help option parsing As in commit d0c05e6f4600f90f7b940eaedf987ba180ae0b65, properly distinguish between the command line option -? and getopt's unknown option marker '?' --- repmgrd.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/repmgrd.c b/repmgrd.c index 3c856d9a..d4bc19ae 100644 --- a/repmgrd.c +++ b/repmgrd.c @@ -124,7 +124,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} }; @@ -158,6 +158,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; @@ -173,13 +190,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); }