mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-21 08:29:39 +08:00
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.
This commit is contained in:
parent
03e56f798e
commit
86947e666d
@ -3190,6 +3190,13 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx)
|
|||||||
gucsource = PGC_S_CLIENT; /* switches came from client */
|
gucsource = PGC_S_CLIENT; /* switches came from client */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_INT_OPTERR
|
||||||
|
/* Turn this off because it's either printed to stderr and not the log
|
||||||
|
* where we'd want it, or argv[0] is now "--single", which would make for a
|
||||||
|
* weird error message. We print our own error message below. */
|
||||||
|
opterr = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse command-line options. CAUTION: keep this in sync with
|
* Parse command-line options. CAUTION: keep this in sync with
|
||||||
* postmaster/postmaster.c (the option sets should not conflict) and with
|
* postmaster/postmaster.c (the option sets should not conflict) and with
|
||||||
@ -3363,33 +3370,39 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx)
|
|||||||
errs++;
|
errs++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (errs)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Should be no more arguments except an optional database name, and
|
* Should be no more arguments except an optional database name, and
|
||||||
* that's only in the secure case.
|
* that's only in the secure case.
|
||||||
*/
|
*/
|
||||||
if (errs || argc - optind > 1 || (argc != optind && !secure))
|
if (!errs && secure && argc - optind >= 1)
|
||||||
|
dbname = strdup(argv[optind++]);
|
||||||
|
else
|
||||||
|
dbname = NULL;
|
||||||
|
|
||||||
|
if (errs || argc != optind)
|
||||||
{
|
{
|
||||||
|
if (errs)
|
||||||
|
optind--; /* complain about the previous argument */
|
||||||
|
|
||||||
/* spell the error message a bit differently depending on context */
|
/* spell the error message a bit differently depending on context */
|
||||||
if (IsUnderPostmaster)
|
if (IsUnderPostmaster)
|
||||||
ereport(FATAL,
|
ereport(FATAL,
|
||||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||||
errmsg("invalid command-line arguments for server process"),
|
errmsg("invalid command-line argument for server process: %s", argv[optind]),
|
||||||
errhint("Try \"%s --help\" for more information.", progname)));
|
errhint("Try \"%s --help\" for more information.", progname)));
|
||||||
else
|
else
|
||||||
ereport(FATAL,
|
ereport(FATAL,
|
||||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||||
errmsg("%s: invalid command-line arguments",
|
errmsg("%s: invalid command-line argument: %s",
|
||||||
progname),
|
progname, argv[optind]),
|
||||||
errhint("Try \"%s --help\" for more information.", progname)));
|
errhint("Try \"%s --help\" for more information.", progname)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc - optind == 1)
|
|
||||||
dbname = strdup(argv[optind]);
|
|
||||||
else
|
|
||||||
dbname = NULL;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reset getopt(3) library so that it will work correctly in subprocesses
|
* Reset getopt(3) library so that it will work correctly in subprocesses
|
||||||
* or when this function is called a second time with another array.
|
* or when this function is called a second time with another array.
|
||||||
|
Loading…
Reference in New Issue
Block a user