mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-27 17:06:29 +00:00
repmgrd: fix parsing of -d/--daemonize option
The getopt API doesn't cope well with optional arguments to short form options, e.g. "-o foo", so we need to check the next argument value to see whether it looks like an option or an actual argument value.
This commit is contained in:
19
repmgrd.c
19
repmgrd.c
@@ -101,7 +101,8 @@ main(int argc, char **argv)
|
|||||||
{"config-file", required_argument, NULL, 'f'},
|
{"config-file", required_argument, NULL, 'f'},
|
||||||
|
|
||||||
/* daemon options */
|
/* daemon options */
|
||||||
{"daemonize", optional_argument, NULL, 'd'},
|
{"daemonize-short", optional_argument, NULL, 'd'},
|
||||||
|
{"daemonize", optional_argument, NULL, OPT_DAEMONIZE},
|
||||||
{"pid-file", required_argument, NULL, 'p'},
|
{"pid-file", required_argument, NULL, 'p'},
|
||||||
{"show-pid-file", no_argument, NULL, 's'},
|
{"show-pid-file", no_argument, NULL, 's'},
|
||||||
{"no-pid-file", no_argument, NULL, OPT_NO_PID_FILE},
|
{"no-pid-file", no_argument, NULL, OPT_NO_PID_FILE},
|
||||||
@@ -134,7 +135,7 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
memset(pid_file, 0, MAXPGPATH);
|
memset(pid_file, 0, MAXPGPATH);
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "?Vf:L:vd:p:m", long_options, &optindex)) != -1)
|
while ((c = getopt_long(argc, argv, "?Vf:L:vdp:m", long_options, &optindex)) != -1)
|
||||||
{
|
{
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
@@ -174,13 +175,16 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
/* daemon options */
|
/* daemon options */
|
||||||
|
|
||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
if (optarg != NULL)
|
daemonize = true;
|
||||||
{
|
|
||||||
daemonize = parse_bool(optarg, "-d/--daemonize", &cli_errors);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case OPT_DAEMONIZE:
|
||||||
|
daemonize = parse_bool(optarg, "-d/--daemonize", &cli_errors);
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
strncpy(pid_file, optarg, MAXPGPATH);
|
strncpy(pid_file, optarg, MAXPGPATH);
|
||||||
break;
|
break;
|
||||||
@@ -763,7 +767,8 @@ show_help(void)
|
|||||||
puts("");
|
puts("");
|
||||||
|
|
||||||
printf(_("Daemon configuration options:\n"));
|
printf(_("Daemon configuration options:\n"));
|
||||||
printf(_(" -d, --daemonize[=true/false]\n"));
|
printf(_(" -d\n"));
|
||||||
|
printf(_(" --daemonize[=true/false]\n"));
|
||||||
printf(_(" detach process from foreground (default: true)\n"));
|
printf(_(" detach process from foreground (default: true)\n"));
|
||||||
printf(_(" -p, --pid-file=PATH use the specified PID file\n"));
|
printf(_(" -p, --pid-file=PATH use the specified PID file\n"));
|
||||||
printf(_(" -s, --show-pid-file show PID file which would be used by the current configuration\n"));
|
printf(_(" -s, --show-pid-file show PID file which would be used by the current configuration\n"));
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "portability/instr_time.h"
|
#include "portability/instr_time.h"
|
||||||
|
|
||||||
#define OPT_NO_PID_FILE 1000
|
#define OPT_NO_PID_FILE 1000
|
||||||
|
#define OPT_DAEMONIZE 1001
|
||||||
|
|
||||||
extern volatile sig_atomic_t got_SIGHUP;
|
extern volatile sig_atomic_t got_SIGHUP;
|
||||||
extern MonitoringState monitoring_state;
|
extern MonitoringState monitoring_state;
|
||||||
|
|||||||
Reference in New Issue
Block a user