From a146e7be893446521362d60d302d50dfe1001f13 Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Tue, 17 Apr 2012 18:37:42 -0400 Subject: 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. --- src/bin/scripts/clusterdb.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'src/bin/scripts/clusterdb.c') 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(); -- cgit v1.2.3