Skip to content

Commit 00be754

Browse files
committed
Split apart pg_upgrade user lookup and root check so '--help' shows
proper default username.
1 parent add8044 commit 00be754

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

contrib/pg_upgrade/option.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ parseCommandLine(migratorContext *ctx, int argc, char *argv[])
4848
};
4949
char option; /* Command line option */
5050
int optindex = 0; /* used by getopt_long */
51-
51+
int user_id;
52+
5253
if (getenv("PGUSER"))
5354
{
5455
pg_free(ctx->user);
@@ -62,6 +63,9 @@ parseCommandLine(migratorContext *ctx, int argc, char *argv[])
6263

6364
ctx->transfer_mode = TRANSFER_MODE_COPY;
6465

66+
/* user lookup and 'root' test must be split because of usage() */
67+
user_id = get_user_info(ctx, &ctx->user);
68+
6569
if (argc > 1)
6670
{
6771
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ||
@@ -77,7 +81,7 @@ parseCommandLine(migratorContext *ctx, int argc, char *argv[])
7781
}
7882
}
7983

80-
if ((get_user_info(ctx, &ctx->user)) == 0)
84+
if (user_id == 0)
8185
pg_log(ctx, PG_FATAL, "%s: cannot be run as root\n", ctx->progname);
8286

8387
#ifndef WIN32

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy