diff options
author | Andrew Dunstan <andrew@dunslane.net> | 2012-04-17 18:37:42 -0400 |
---|---|---|
committer | Andrew Dunstan <andrew@dunslane.net> | 2012-04-17 18:37:42 -0400 |
commit | a146e7be893446521362d60d302d50dfe1001f13 (patch) | |
tree | 0abc6a97b89e9706b9d21282bf7f3c7f61b84702 /src/bin/scripts/clusterdb.c | |
parent | 10fcfada235af6186c9474230483ab0fe5c9610d (diff) | |
download | postgresql-a146e7be893446521362d60d302d50dfe1001f13.tar.gz postgresql-a146e7be893446521362d60d302d50dfe1001f13.zip |
Don't override arguments set via options with positional arguments.
A number of utility programs were rather careless about paremeters
that can be set via both an option argument and a positional
argument. This leads to results which can violate the Principal
Of Least Astonishment. These changes refuse to use positional
arguments to override settings that have been made via positional
arguments. The changes are backpatched to all live branches.
Diffstat (limited to 'src/bin/scripts/clusterdb.c')
-rw-r--r-- | src/bin/scripts/clusterdb.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/bin/scripts/clusterdb.c b/src/bin/scripts/clusterdb.c index f4c317ae149..624886e5c9e 100644 --- a/src/bin/scripts/clusterdb.c +++ b/src/bin/scripts/clusterdb.c @@ -106,18 +106,22 @@ main(int argc, char *argv[]) } } - switch (argc - optind) + /* + * Non-option argument specifies database name + * as long as it wasn't already specified with -d / --dbname + */ + if (optind < argc && dbname == NULL) { - case 0: - break; - case 1: - dbname = argv[optind]; - break; - default: - fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"), - progname, argv[optind + 1]); - fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); - exit(1); + dbname = argv[optind]; + optind++; + } + + if (optind < argc) + { + fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"), + progname, argv[optind + 1]); + fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); + exit(1); } setup_cancel_handler(); |