Skip to content

Commit c2242d3

Browse files
committed
pg_receivewal, pg_recvlogical: allow canceling initial password prompt.
Previously it was impossible to terminate these programs via control-C while they were prompting for a password. We can fix that trivially for their initial password prompts, by moving setup of the SIGINT handler from just before to just after their initial GetConnection() calls. This fix doesn't permit escaping out of later re-prompts, but those should be exceedingly rare, since the user's password or the server's authentication setup would have to have changed meanwhile. We considered applying a fix similar to commit 46d665b, but that seemed more complicated than it'd be worth. Moreover, this way is back-patchable, which that wasn't. The misbehavior exists in all supported versions, so back-patch to all. Tom Lane and Nathan Bossart Discussion: https://postgr.es/m/747443.1635536754@sss.pgh.pa.us
1 parent dff01e4 commit c2242d3

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/bin/pg_basebackup/pg_receivewal.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,10 +684,6 @@ main(int argc, char **argv)
684684
close_destination_dir(dir, basedir);
685685
}
686686

687-
#ifndef WIN32
688-
pqsignal(SIGINT, sigint_handler);
689-
#endif
690-
691687
/*
692688
* Obtain a connection before doing anything.
693689
*/
@@ -696,6 +692,14 @@ main(int argc, char **argv)
696692
/* error message already written in GetConnection() */
697693
exit(1);
698694

695+
/*
696+
* Trap signals. (Don't do this until after the initial password prompt,
697+
* if one is needed, in GetConnection.)
698+
*/
699+
#ifndef WIN32
700+
pqsignal(SIGINT, sigint_handler);
701+
#endif
702+
699703
/*
700704
* Run IDENTIFY_SYSTEM to make sure we've successfully have established a
701705
* replication connection and haven't connected using a database specific

src/bin/pg_basebackup/pg_recvlogical.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@ StreamLogicalLog(void)
220220
output_written_lsn = InvalidXLogRecPtr;
221221
output_fsync_lsn = InvalidXLogRecPtr;
222222

223-
query = createPQExpBuffer();
224-
225223
/*
226224
* Connect in replication mode to the server
227225
*/
@@ -241,6 +239,7 @@ StreamLogicalLog(void)
241239
replication_slot);
242240

243241
/* Initiate the replication stream at specified location */
242+
query = createPQExpBuffer();
244243
appendPQExpBuffer(query, "START_REPLICATION SLOT \"%s\" LOGICAL %X/%X",
245244
replication_slot, (uint32) (startpos >> 32), (uint32) startpos);
246245

@@ -956,21 +955,24 @@ main(int argc, char **argv)
956955
exit(1);
957956
}
958957

959-
#ifndef WIN32
960-
pqsignal(SIGINT, sigint_handler);
961-
pqsignal(SIGHUP, sighup_handler);
962-
#endif
963-
964958
/*
965-
* Obtain a connection to server. This is not really necessary but it
966-
* helps to get more precise error messages about authentication, required
967-
* GUC parameters and such.
959+
* Obtain a connection to server. Notably, if we need a password, we want
960+
* to collect it from the user immediately.
968961
*/
969962
conn = GetConnection();
970963
if (!conn)
971964
/* Error message already written in GetConnection() */
972965
exit(1);
973966

967+
/*
968+
* Trap signals. (Don't do this until after the initial password prompt,
969+
* if one is needed, in GetConnection.)
970+
*/
971+
#ifndef WIN32
972+
pqsignal(SIGINT, sigint_handler);
973+
pqsignal(SIGHUP, sighup_handler);
974+
#endif
975+
974976
/*
975977
* Run IDENTIFY_SYSTEM to make sure we connected using a database specific
976978
* replication connection.

0 commit comments

Comments
 (0)