@@ -3190,6 +3190,13 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx)
31903190gucsource = 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)
33633370errs ++ ;
33643371break ;
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 */
33753393if (IsUnderPostmaster )
33763394ereport (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 ] ),
33793397errhint ("Try \"%s --help\" for more information." ,progname )));
33803398else
33813399ereport (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 ] ),
33853403errhint ("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.