From 5624055762af88cf8e8e844d83959ffcf2be2ab4 Mon Sep 17 00:00:00 2001 From: Gurjeet Singh Date: Wed, 7 Jul 2021 01:50:41 +0000 Subject: [PATCH v1 2/2] Warn if --sync-only is used with other options --- src/bin/initdb/initdb.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 05a98b9ade..fe2c9684bf 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -2960,6 +2960,7 @@ main(int argc, char *argv[]) char *effective_user; PQExpBuffer start_db_cmd; char pg_ctl_path[MAXPGPATH]; + bool pg_data_opt_used = false; /* * Ensure that buffering behavior of stdout matches what it is in @@ -3014,6 +3015,7 @@ main(int argc, char *argv[]) break; case 'D': pg_data = pg_strdup(optarg); + pg_data_opt_used = true; break; case 'E': encoding = pg_strdup(optarg); @@ -3127,6 +3129,18 @@ main(int argc, char *argv[]) /* If we only need to fsync, just do it and exit */ if (sync_only) { + + // 2 => 1 for command itself, and one for --sync-data option + int valid_argc = 2 + pg_data_opt_used + (pg_data != NULL); + + // Ensure that there were no other options specified + if (argc > valid_argc) + { + // Maybe we should _error_ and exit?! + pg_log_warning("too many command-line arguments (--sync-only ignores all other options)"); + //exit(1); + } + setup_pgdata(); /* must check that directory is readable */ -- 2.30.0