* from ExtraOptions is (strlen(ExtraOptions) + 1) / 2; see
* pg_split_opts().
*/
- maxac = 5; /* for fixed args supplied below */
+ maxac = 2; /* for fixed args supplied below */
maxac += (strlen(ExtraOptions) + 1) / 2;
av = (char **) MemoryContextAlloc(TopMemoryContext,
*/
pg_split_opts(av, &ac, ExtraOptions);
- /*
- * Tell the backend which database to use.
- */
- av[ac++] = port->database_name;
-
av[ac] = NULL;
Assert(ac < maxac);
*/
MemoryContextSwitchTo(TopMemoryContext);
- return (PostgresMain(ac, av, port->user_name));
+ return PostgresMain(ac, av, port->database_name, port->user_name);
}
* coming from the client, or PGC_SUSET for insecure options coming from
* a superuser client.
*
- * Returns the database name extracted from the command line, if any.
+ * If a database name is present in the command line arguments, it's
+ * returned into *dbname (this is allowed only if *dbname is initially NULL).
* ----------------------------------------------------------------
*/
-const char *
-process_postgres_switches(int argc, char *argv[], GucContext ctx)
+void
+process_postgres_switches(int argc, char *argv[], GucContext ctx,
+ const char **dbname)
{
- const char *dbname;
bool secure = (ctx == PGC_POSTMASTER);
int errs = 0;
GucSource gucsource;
case 'b':
/* Undocumented flag used for binary upgrades */
- IsBinaryUpgrade = true;
+ if (secure)
+ IsBinaryUpgrade = true;
break;
case 'C':
break;
case 'E':
- EchoQuery = true;
+ if (secure)
+ EchoQuery = true;
break;
case 'e':
break;
case 'j':
- UseNewLine = 0;
+ if (secure)
+ UseNewLine = 0;
break;
case 'k':
}
/*
- * Should be no more arguments except an optional database name, and
- * that's only in the secure case.
+ * Optional database name should be there only if *dbname is NULL.
*/
- if (!errs && secure && argc - optind >= 1)
- dbname = strdup(argv[optind++]);
- else
- dbname = NULL;
+ if (!errs && dbname && *dbname == NULL && argc - optind >= 1)
+ *dbname = strdup(argv[optind++]);
if (errs || argc != optind)
{
#ifdef HAVE_INT_OPTRESET
optreset = 1; /* some systems need this too */
#endif
-
- return dbname;
}
*
* argc/argv are the command line arguments to be used. (When being forked
* by the postmaster, these are not the original argv array of the process.)
- * username is the (possibly authenticated) PostgreSQL user name to be used
- * for the session.
+ * dbname is the name of the database to connect to, or NULL if the database
+ * name should be extracted from the command line arguments or defaulted.
+ * username is the PostgreSQL user name to be used for the session.
* ----------------------------------------------------------------
*/
int
-PostgresMain(int argc, char *argv[], const char *username)
+PostgresMain(int argc, char *argv[],
+ const char *dbname,
+ const char *username)
{
- const char *dbname;
int firstchar;
StringInfoData input_message;
sigjmp_buf local_sigjmp_buf;
/*
* Parse command-line options.
*/
- dbname = process_postgres_switches(argc, argv, PGC_POSTMASTER);
+ process_postgres_switches(argc, argv, PGC_POSTMASTER, &dbname);
/* Must have gotten a database name, or have a default (the username) */
if (dbname == NULL)
* handler */
extern void prepare_for_client_read(void);
extern void client_read_ended(void);
-extern const char *process_postgres_switches(int argc, char *argv[],
- GucContext ctx);
-extern int PostgresMain(int argc, char *argv[], const char *username);
+extern void process_postgres_switches(int argc, char *argv[],
+ GucContext ctx, const char **dbname);
+extern int PostgresMain(int argc, char *argv[],
+ const char *dbname, const char *username);
extern long get_stack_depth_rlimit(void);
extern void ResetUsage(void);
extern void ShowUsage(const char *title);