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

Commit 86947e6

Browse files
committed
Add more detail to error message for invalid arguments for server process
It now prints the argument that was at fault. Also fix a small misbehavior where the error message issued by getopt() would complain about a program named "--single", because that's what argv[0] is in the server process.
1 parent 03e56f7 commit 86947e6

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/backend/tcop/postgres.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,6 +3190,13 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx)
31903190
gucsource = PGC_S_CLIENT; /* switches came from client */
31913191
}
31923192

3193+
#ifdef HAVE_INT_OPTERR
3194+
/* Turn this off because it's either printed to stderr and not the log
3195+
* where we'd want it, or argv[0] is now "--single", which would make for a
3196+
* weird error message. We print our own error message below. */
3197+
opterr = 0;
3198+
#endif
3199+
31933200
/*
31943201
* Parse command-line options. CAUTION: keep this in sync with
31953202
* postmaster/postmaster.c (the option sets should not conflict) and with
@@ -3363,33 +3370,39 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx)
33633370
errs++;
33643371
break;
33653372
}
3373+
3374+
if (errs)
3375+
break;
33663376
}
33673377

33683378
/*
33693379
* Should be no more arguments except an optional database name, and
33703380
* that's only in the secure case.
33713381
*/
3372-
if (errs || argc - optind > 1 || (argc != optind && !secure))
3382+
if (!errs && secure && argc - optind >= 1)
3383+
dbname = strdup(argv[optind++]);
3384+
else
3385+
dbname = NULL;
3386+
3387+
if (errs || argc != optind)
33733388
{
3389+
if (errs)
3390+
optind--; /* complain about the previous argument */
3391+
33743392
/* spell the error message a bit differently depending on context */
33753393
if (IsUnderPostmaster)
33763394
ereport(FATAL,
33773395
(errcode(ERRCODE_SYNTAX_ERROR),
3378-
errmsg("invalid command-line arguments for server process"),
3396+
errmsg("invalid command-line argument for server process: %s", argv[optind]),
33793397
errhint("Try \"%s --help\" for more information.", progname)));
33803398
else
33813399
ereport(FATAL,
33823400
(errcode(ERRCODE_SYNTAX_ERROR),
3383-
errmsg("%s: invalid command-line arguments",
3384-
progname),
3401+
errmsg("%s: invalid command-line argument: %s",
3402+
progname, argv[optind]),
33853403
errhint("Try \"%s --help\" for more information.", progname)));
33863404
}
33873405

3388-
if (argc - optind == 1)
3389-
dbname = strdup(argv[optind]);
3390-
else
3391-
dbname = NULL;
3392-
33933406
/*
33943407
* Reset getopt(3) library so that it will work correctly in subprocesses
33953408
* or when this function is called a second time with another array.

0 commit comments

Comments
 (0)