@@ -3190,6 +3190,13 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx)
3190
3190
gucsource = PGC_S_CLIENT ; /* switches came from client */
3191
3191
}
3192
3192
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
+
3193
3200
/*
3194
3201
* Parse command-line options. CAUTION: keep this in sync with
3195
3202
* postmaster/postmaster.c (the option sets should not conflict) and with
@@ -3363,33 +3370,39 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx)
3363
3370
errs ++ ;
3364
3371
break ;
3365
3372
}
3373
+
3374
+ if (errs )
3375
+ break ;
3366
3376
}
3367
3377
3368
3378
/*
3369
3379
* Should be no more arguments except an optional database name, and
3370
3380
* that's only in the secure case.
3371
3381
*/
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 )
3373
3388
{
3389
+ if (errs )
3390
+ optind -- ; /* complain about the previous argument */
3391
+
3374
3392
/* spell the error message a bit differently depending on context */
3375
3393
if (IsUnderPostmaster )
3376
3394
ereport (FATAL ,
3377
3395
(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 ] ),
3379
3397
errhint ("Try \"%s --help\" for more information." , progname )));
3380
3398
else
3381
3399
ereport (FATAL ,
3382
3400
(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 ] ),
3385
3403
errhint ("Try \"%s --help\" for more information." , progname )));
3386
3404
}
3387
3405
3388
- if (argc - optind == 1 )
3389
- dbname = strdup (argv [optind ]);
3390
- else
3391
- dbname = NULL ;
3392
-
3393
3406
/*
3394
3407
* Reset getopt(3) library so that it will work correctly in subprocesses
3395
3408
* or when this function is called a second time with another array.
0 commit comments