Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit86947e6

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 bygetopt() would complain about a program named "--single", becausethat's what argv[0] is in the server process.
1 parent03e56f7 commit86947e6

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+
#ifdefHAVE_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-linearguments for server process"),
3396+
errmsg("invalid command-lineargument 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-linearguments",
3384-
progname),
3401+
errmsg("%s: invalid command-lineargument: %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)

[8]ページ先頭

©2009-2025 Movatter.jp