Simplify option handling in pg_ctl.
Now that the in-tree getopt_long() moves non-options to the end of argv (see commit 411b720343), we can remove pg_ctl's workaround for getopt_long() implementations that don't reorder argv. Reviewed-by: Michael Paquier Discussion: https://postgr.es/m/20230713034903.GA991765%40nathanxps13
This commit is contained in:
parent
e08d74ca13
commit
03d1080d8a
@ -2260,17 +2260,7 @@ main(int argc, char **argv)
|
|||||||
if (env_wait != NULL)
|
if (env_wait != NULL)
|
||||||
wait_seconds = atoi(env_wait);
|
wait_seconds = atoi(env_wait);
|
||||||
|
|
||||||
/*
|
|
||||||
* 'Action' can be before or after args so loop over both. Some
|
|
||||||
* getopt_long() implementations will reorder argv[] to place all flags
|
|
||||||
* first (GNU?), but we don't rely on it. Our /port version doesn't do
|
|
||||||
* that.
|
|
||||||
*/
|
|
||||||
optind = 1;
|
|
||||||
|
|
||||||
/* process command-line options */
|
/* process command-line options */
|
||||||
while (optind < argc)
|
|
||||||
{
|
|
||||||
while ((c = getopt_long(argc, argv, "cD:e:l:m:N:o:p:P:sS:t:U:wW",
|
while ((c = getopt_long(argc, argv, "cD:e:l:m:N:o:p:P:sS:t:U:wW",
|
||||||
long_options, &option_index)) != -1)
|
long_options, &option_index)) != -1)
|
||||||
{
|
{
|
||||||
@ -2285,9 +2275,8 @@ main(int argc, char **argv)
|
|||||||
setenv("PGDATA", pgdata_D, 1);
|
setenv("PGDATA", pgdata_D, 1);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We could pass PGDATA just in an environment
|
* We could pass PGDATA just in an environment variable
|
||||||
* variable but we do -D too for clearer postmaster
|
* but we do -D too for clearer postmaster 'ps' display
|
||||||
* 'ps' display
|
|
||||||
*/
|
*/
|
||||||
pgdata_opt = psprintf("-D \"%s\" ", pgdata_D);
|
pgdata_opt = psprintf("-D \"%s\" ", pgdata_D);
|
||||||
free(pgdata_D);
|
free(pgdata_D);
|
||||||
@ -2365,13 +2354,6 @@ main(int argc, char **argv)
|
|||||||
/* Process an action */
|
/* Process an action */
|
||||||
if (optind < argc)
|
if (optind < argc)
|
||||||
{
|
{
|
||||||
if (ctl_command != NO_COMMAND)
|
|
||||||
{
|
|
||||||
write_stderr(_("%s: too many command-line arguments (first is \"%s\")\n"), progname, argv[optind]);
|
|
||||||
do_advice();
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(argv[optind], "init") == 0
|
if (strcmp(argv[optind], "init") == 0
|
||||||
|| strcmp(argv[optind], "initdb") == 0)
|
|| strcmp(argv[optind], "initdb") == 0)
|
||||||
ctl_command = INIT_COMMAND;
|
ctl_command = INIT_COMMAND;
|
||||||
@ -2417,6 +2399,12 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
optind++;
|
optind++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (optind < argc)
|
||||||
|
{
|
||||||
|
write_stderr(_("%s: too many command-line arguments (first is \"%s\")\n"), progname, argv[optind]);
|
||||||
|
do_advice();
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctl_command == NO_COMMAND)
|
if (ctl_command == NO_COMMAND)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user