Skip to content

Commit 282b6d0

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 92e7079 commit 282b6d0

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

src/bin/pg_basebackup/pg_receivewal.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -917,10 +917,6 @@ main(int argc, char **argv)
917917
close_destination_dir(dir, basedir);
918918
}
919919

920-
#ifndef WIN32
921-
pqsignal(SIGINT, sigint_handler);
922-
#endif
923-
924920
/*
925921
* Obtain a connection before doing anything.
926922
*/
@@ -930,6 +926,14 @@ main(int argc, char **argv)
930926
exit(1);
931927
atexit(disconnect_atexit);
932928

929+
/*
930+
* Trap signals. (Don't do this until after the initial password prompt,
931+
* if one is needed, in GetConnection.)
932+
*/
933+
#ifndef WIN32
934+
pqsignal(SIGINT, sigint_handler);
935+
#endif
936+
933937
/*
934938
* Run IDENTIFY_SYSTEM to make sure we've successfully have established a
935939
* replication connection and haven't connected using a database specific

src/bin/pg_basebackup/pg_recvlogical.c

+12-11
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,6 @@ StreamLogicalLog(void)
216216
output_written_lsn = InvalidXLogRecPtr;
217217
output_fsync_lsn = InvalidXLogRecPtr;
218218

219-
query = createPQExpBuffer();
220-
221219
/*
222220
* Connect in replication mode to the server
223221
*/
@@ -236,6 +234,7 @@ StreamLogicalLog(void)
236234
replication_slot);
237235

238236
/* Initiate the replication stream at specified location */
237+
query = createPQExpBuffer();
239238
appendPQExpBuffer(query, "START_REPLICATION SLOT \"%s\" LOGICAL %X/%X",
240239
replication_slot, LSN_FORMAT_ARGS(startpos));
241240

@@ -932,23 +931,25 @@ main(int argc, char **argv)
932931
exit(1);
933932
}
934933

935-
936-
#ifndef WIN32
937-
pqsignal(SIGINT, sigint_handler);
938-
pqsignal(SIGHUP, sighup_handler);
939-
#endif
940-
941934
/*
942-
* Obtain a connection to server. This is not really necessary but it
943-
* helps to get more precise error messages about authentication, required
944-
* GUC parameters and such.
935+
* Obtain a connection to server. Notably, if we need a password, we want
936+
* to collect it from the user immediately.
945937
*/
946938
conn = GetConnection();
947939
if (!conn)
948940
/* Error message already written in GetConnection() */
949941
exit(1);
950942
atexit(disconnect_atexit);
951943

944+
/*
945+
* Trap signals. (Don't do this until after the initial password prompt,
946+
* if one is needed, in GetConnection.)
947+
*/
948+
#ifndef WIN32
949+
pqsignal(SIGINT, sigint_handler);
950+
pqsignal(SIGHUP, sighup_handler);
951+
#endif
952+
952953
/*
953954
* Run IDENTIFY_SYSTEM to make sure we connected using a database specific
954955
* replication connection.

0 commit comments

Comments
 (0)