Skip to content

Commit 14e5110

Browse files
committed
Call on_cleanup() within on_interrupt() to correctly handle simple_prompt() interrupt
1 parent be5129d commit 14e5110

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/utils/pgut.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static PGcancel *volatile cancel_conn = NULL;
4747
/* Interrupted by SIGINT (Ctrl+C) ? */
4848
bool interrupted = false;
4949
bool in_cleanup = false;
50+
bool in_password = false;
5051

5152
static bool parse_pair(const char buffer[], char key[], char value[]);
5253

@@ -1080,7 +1081,8 @@ parse_pair(const char buffer[], char key[], char value[])
10801081
static void
10811082
prompt_for_password(const char *username)
10821083
{
1083-
pqsignal(SIGINT, oldhandler);
1084+
in_password = true;
1085+
10841086
if (password)
10851087
{
10861088
free(password);
@@ -1107,7 +1109,8 @@ prompt_for_password(const char *username)
11071109
password = simple_prompt(message, 100, false);
11081110
}
11091111
#endif
1110-
init_cancel_handler();
1112+
1113+
in_password = false;
11111114
}
11121115

11131116
PGconn *
@@ -1527,6 +1530,15 @@ on_interrupt(void)
15271530
/* Set interruped flag */
15281531
interrupted = true;
15291532

1533+
/* User promts password, call on_cleanup() byhand */
1534+
if (in_password)
1535+
{
1536+
on_cleanup();
1537+
1538+
pqsignal(SIGINT, oldhandler);
1539+
kill(0, SIGINT);
1540+
}
1541+
15301542
/* Send QueryCancel if we are processing a database query */
15311543
if (!in_cleanup && cancel_conn != NULL &&
15321544
PQcancel(cancel_conn, errbuf, sizeof(errbuf)))

src/utils/pgut.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ extern bool prompt_password;
105105

106106
extern bool interrupted;
107107
extern bool in_cleanup;
108+
extern bool in_password; /* User prompts password */
108109

109110
extern int pgut_getopt(int argc, char **argv, pgut_option options[]);
110111
extern void pgut_readopt(const char *path, pgut_option options[], int elevel);

0 commit comments

Comments
 (0)