summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2021-11-21 14:13:35 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2021-11-21 14:13:35 -0500
commit3ce5d0884c564cbb1de1e6997c2b557f558e6398 (patch)
tree520630b2af70cb149840f8358bec5b2970924d32 /src
parent13799bb93866a3fbe02c0811b9c7e3570700a7b5 (diff)
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 46d665bc2, 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
Diffstat (limited to 'src')
-rw-r--r--src/bin/pg_basebackup/pg_receivewal.c12
-rw-r--r--src/bin/pg_basebackup/pg_recvlogical.c22
2 files changed, 20 insertions, 14 deletions
diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c
index 9ea61d5a5d4..03bfbb8c77b 100644
--- a/src/bin/pg_basebackup/pg_receivewal.c
+++ b/src/bin/pg_basebackup/pg_receivewal.c
@@ -644,10 +644,6 @@ main(int argc, char **argv)
close_destination_dir(dir, basedir);
}
-#ifndef WIN32
- pqsignal(SIGINT, sigint_handler);
-#endif
-
/*
* Obtain a connection before doing anything.
*/
@@ -657,6 +653,14 @@ main(int argc, char **argv)
exit(1);
/*
+ * Trap signals. (Don't do this until after the initial password prompt,
+ * if one is needed, in GetConnection.)
+ */
+#ifndef WIN32
+ pqsignal(SIGINT, sigint_handler);
+#endif
+
+ /*
* Run IDENTIFY_SYSTEM to make sure we've successfully have established a
* replication connection and haven't connected using a database specific
* connection.
diff --git a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup/pg_recvlogical.c
index adb9f800c71..93c6c831dcc 100644
--- a/src/bin/pg_basebackup/pg_recvlogical.c
+++ b/src/bin/pg_basebackup/pg_recvlogical.c
@@ -219,8 +219,6 @@ StreamLogicalLog(void)
output_written_lsn = InvalidXLogRecPtr;
output_fsync_lsn = InvalidXLogRecPtr;
- query = createPQExpBuffer();
-
/*
* Connect in replication mode to the server
*/
@@ -240,6 +238,7 @@ StreamLogicalLog(void)
replication_slot);
/* Initiate the replication stream at specified location */
+ query = createPQExpBuffer();
appendPQExpBuffer(query, "START_REPLICATION SLOT \"%s\" LOGICAL %X/%X",
replication_slot, (uint32) (startpos >> 32), (uint32) startpos);
@@ -955,15 +954,9 @@ main(int argc, char **argv)
exit(1);
}
-#ifndef WIN32
- pqsignal(SIGINT, sigint_handler);
- pqsignal(SIGHUP, sighup_handler);
-#endif
-
/*
- * Obtain a connection to server. This is not really necessary but it
- * helps to get more precise error messages about authentication, required
- * GUC parameters and such.
+ * Obtain a connection to server. Notably, if we need a password, we want
+ * to collect it from the user immediately.
*/
conn = GetConnection();
if (!conn)
@@ -971,6 +964,15 @@ main(int argc, char **argv)
exit(1);
/*
+ * Trap signals. (Don't do this until after the initial password prompt,
+ * if one is needed, in GetConnection.)
+ */
+#ifndef WIN32
+ pqsignal(SIGINT, sigint_handler);
+ pqsignal(SIGHUP, sighup_handler);
+#endif
+
+ /*
* Run IDENTIFY_SYSTEM to make sure we connected using a database specific
* replication connection.
*/