aboutsummaryrefslogtreecommitdiff
path: root/src/bin/scripts/clusterdb.c
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2012-04-17 18:30:34 -0400
committerAndrew Dunstan <andrew@dunslane.net>2012-04-17 18:30:34 -0400
commit1b37a8c3cc4f0615f80d6007e2bbd47c6bd7e1e3 (patch)
treef8757aec163b2d6582031e1d39ea5c63e4680a5c /src/bin/scripts/clusterdb.c
parentfe546f3da6a5ff1d879f587728f74ec457f0ee5f (diff)
downloadpostgresql-1b37a8c3cc4f0615f80d6007e2bbd47c6bd7e1e3.tar.gz
postgresql-1b37a8c3cc4f0615f80d6007e2bbd47c6bd7e1e3.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.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/bin/scripts/clusterdb.c b/src/bin/scripts/clusterdb.c
index b01f91c1d6e..0f711e870b3 100644
--- a/src/bin/scripts/clusterdb.c
+++ b/src/bin/scripts/clusterdb.c
@@ -112,18 +112,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();