Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9684e42

Browse files
committed
Error out on too many command-line arguments
Fix up oid2name, pg_upgrade, and pgbench to error out on too many command-line arguments. This makes it match the behavior of other PostgreSQL programs. Author: Peter Eisentraut, Ibrar Ahmed Discussion: https://www.postgresql.org/message-id/flat/f2554627-04e7-383a-ef01-ab99bb6a291c%402ndquadrant.com
1 parent 317b3d7 commit 9684e42

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

contrib/oid2name/oid2name.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@ get_opts(int argc, char **argv, struct options *my_opts)
185185
exit(1);
186186
}
187187
}
188+
189+
if (optind < argc)
190+
{
191+
fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"),
192+
progname, argv[optind]);
193+
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
194+
exit(1);
195+
}
188196
}
189197

190198
static void

src/bin/pg_upgrade/option.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ parseCommandLine(int argc, char *argv[])
218218
}
219219
}
220220

221+
if (optind < argc)
222+
pg_fatal("too many command-line arguments (first is \"%s\")\n", argv[optind]);
223+
221224
if ((log_opts.internal = fopen_priv(INTERNAL_LOG_FILE, "a")) == NULL)
222225
pg_fatal("could not open log file \"%s\": %m\n", INTERNAL_LOG_FILE);
223226

src/bin/pgbench/pgbench.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5540,7 +5540,7 @@ main(int argc, char **argv)
55405540
throttle_delay *= nthreads;
55415541

55425542
if (argc > optind)
5543-
dbName = argv[optind];
5543+
dbName = argv[optind++];
55445544
else
55455545
{
55465546
if ((env = getenv("PGDATABASE")) != NULL && *env != '\0')
@@ -5551,6 +5551,14 @@ main(int argc, char **argv)
55515551
dbName = "";
55525552
}
55535553

5554+
if (optind < argc)
5555+
{
5556+
fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"),
5557+
progname, argv[optind]);
5558+
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
5559+
exit(1);
5560+
}
5561+
55545562
if (is_init_mode)
55555563
{
55565564
if (benchmarking_option_set)

0 commit comments

Comments
 (0)