Skip to content

Commit 2093196

Browse files
committed
Merge commit 'd64dec91526f9287ee66b64bfcbda2e584eb47b6' into REL0_5
2 parents 41b8800 + d64dec9 commit 2093196

File tree

1 file changed

+22
-32
lines changed

1 file changed

+22
-32
lines changed

xlogdump_oid2name.c

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -105,51 +105,41 @@ cache_put(Oid oid, char *name)
105105
bool
106106
DBConnect(const char *host, const char *port, char *database, const char *user)
107107
{
108-
char *password = NULL;
109-
char *password_prompt = NULL;
110-
bool need_pass;
111-
112108
pghost = strdup(host);
113109
pgport = strdup(port);
114110
pguser = strdup(user);
111+
pgpass = NULL;
112+
113+
retry_login:
114+
conn = PQsetdbLogin(pghost,
115+
pgport,
116+
NULL,
117+
NULL,
118+
database,
119+
pguser,
120+
pgpass);
115121

116-
/* loop until we have a password if requested by backend */
117-
do
122+
if (PQstatus(conn) == CONNECTION_BAD)
118123
{
119-
need_pass = false;
120-
121-
conn = PQsetdbLogin(host,
122-
port,
123-
NULL,
124-
NULL,
125-
database,
126-
user,
127-
password);
128-
129-
if (PQstatus(conn) == CONNECTION_BAD &&
130-
strcmp(PQerrorMessage(conn), PQnoPasswordSupplied) == 0 &&
131-
!feof(stdin))
124+
/* wait a password if required to login, then retry. */
125+
if (strcmp(PQerrorMessage(conn), PQnoPasswordSupplied) == 0 &&
126+
!feof(stdin))
132127
{
133128
PQfinish(conn);
134-
need_pass = true;
135-
free(password);
136-
password = NULL;
137-
printf("\nPassword: ");
138-
password = simple_prompt(password_prompt, 100, false);
129+
conn = NULL;
130+
pgpass = simple_prompt("Password: ", 100, false);
131+
goto retry_login;
139132
}
140-
} while (need_pass);
141133

142-
if (password)
143-
pgpass = strdup(password);
144-
145-
/* Check to see that the backend connection was successfully made */
146-
if (PQstatus(conn) == CONNECTION_BAD)
147-
{
148134
fprintf(stderr, "Connection to database failed: %s",
149135
PQerrorMessage(conn));
136+
137+
PQfinish(conn);
138+
conn = NULL;
139+
150140
return false;
151141
}
152-
142+
153143
return true;
154144
}
155145

0 commit comments

Comments
 (0)