diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2019-06-19 21:43:31 +0200 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2019-06-19 21:50:24 +0200 |
commit | aba78ab4a9509e7ed92acefd707a99425568f49f (patch) | |
tree | 04762d26c81ac248c52a7f9e5c54fc456d0db808 | |
parent | dfd79e2d0e8f399785ca2f7c659b45fd620cba17 (diff) | |
download | postgresql-aba78ab4a9509e7ed92acefd707a99425568f49f.tar.gz postgresql-aba78ab4a9509e7ed92acefd707a99425568f49f.zip |
pg_upgrade: Improve invalid option handling
Currently, calling pg_upgrade with an invalid command-line option
aborts pg_upgrade but leaves a pg_upgrade_internal.log file lying
around. Reorder things a bit so that that file is not created until
all the options have been parsed.
Discussion: https://www.postgresql.org/message-id/24c8bd05-aed1-6301-919d-8acbabdb8c24@2ndquadrant.com
-rw-r--r-- | src/bin/pg_upgrade/option.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/bin/pg_upgrade/option.c b/src/bin/pg_upgrade/option.c index 171aaa8f13d..873d1d07e48 100644 --- a/src/bin/pg_upgrade/option.c +++ b/src/bin/pg_upgrade/option.c @@ -101,9 +101,6 @@ parseCommandLine(int argc, char *argv[]) if (os_user_effective_id == 0) pg_fatal("%s: cannot be run as root\n", os_info.progname); - if ((log_opts.internal = fopen_priv(INTERNAL_LOG_FILE, "a")) == NULL) - pg_fatal("could not write to log file \"%s\"\n", INTERNAL_LOG_FILE); - while ((option = getopt_long(argc, argv, "d:D:b:B:cj:ko:O:p:P:rs:U:v", long_options, &optindex)) != -1) { @@ -205,7 +202,6 @@ parseCommandLine(int argc, char *argv[]) break; case 'v': - pg_log(PG_REPORT, "Running in verbose mode\n"); log_opts.verbose = true; break; @@ -214,12 +210,18 @@ parseCommandLine(int argc, char *argv[]) break; default: - pg_fatal("Try \"%s --help\" for more information.\n", - os_info.progname); - break; + fprintf(stderr, _("Try \"%s --help\" for more information.\n"), + os_info.progname); + exit(1); } } + if ((log_opts.internal = fopen_priv(INTERNAL_LOG_FILE, "a")) == NULL) + pg_fatal("could not write to log file \"%s\"\n", INTERNAL_LOG_FILE); + + if (log_opts.verbose) + pg_log(PG_REPORT, "Running in verbose mode\n"); + /* label start of upgrade in logfiles */ for (filename = output_files; *filename != NULL; filename++) { |