else
{
char *result;
+ PromptInterruptContext prompt_ctx;
+
+ /* Set up to let SIGINT cancel simple_prompt_extended() */
+ prompt_ctx.jmpbuf = sigint_interrupt_jmp;
+ prompt_ctx.enabled = &sigint_interrupt_enabled;
+ prompt_ctx.canceled = false;
if (arg2)
{
if (!pset.inputfile)
{
- result = simple_prompt(prompt_text, true);
+ result = simple_prompt_extended(prompt_text, true, &prompt_ctx);
}
else
{
}
}
- if (result &&
- !SetVariable(pset.vars, opt, result))
+ if (prompt_ctx.canceled ||
+ (result && !SetVariable(pset.vars, opt, result)))
success = false;
if (result)
/*
* Ask the user for a password; 'username' is the username the
- * password is for, if one has been explicitly specified. Returns a
- * malloc'd string.
+ * password is for, if one has been explicitly specified.
+ * Returns a malloc'd string.
+ * If 'canceled' is provided, *canceled will be set to true if the prompt
+ * is canceled via SIGINT, and to false otherwise.
*/
static char *
-prompt_for_password(const char *username)
+prompt_for_password(const char *username, bool *canceled)
{
char *result;
+ PromptInterruptContext prompt_ctx;
+
+ /* Set up to let SIGINT cancel simple_prompt_extended() */
+ prompt_ctx.jmpbuf = sigint_interrupt_jmp;
+ prompt_ctx.enabled = &sigint_interrupt_enabled;
+ prompt_ctx.canceled = false;
if (username == NULL || username[0] == '\0')
- result = simple_prompt("Password: ", false);
+ result = simple_prompt_extended("Password: ", false, &prompt_ctx);
else
{
char *prompt_text;
prompt_text = psprintf(_("Password for user %s: "), username);
- result = simple_prompt(prompt_text, false);
+ result = simple_prompt_extended(prompt_text, false, &prompt_ctx);
free(prompt_text);
}
+
+ if (canceled)
+ *canceled = prompt_ctx.canceled;
+
return result;
}
*/
if (pset.getPassword == TRI_YES && success)
{
+ bool canceled = false;
+
/*
* If a connstring or URI is provided, we don't know which username
* will be used, since we haven't dug that out of the connstring.
* not seem worth working harder, since this getPassword setting is
* normally only used in noninteractive cases.
*/
- password = prompt_for_password(has_connection_string ? NULL : user);
+ password = prompt_for_password(has_connection_string ? NULL : user,
+ &canceled);
+ success = !canceled;
}
/*
*/
if (!password && PQconnectionNeedsPassword(n_conn) && pset.getPassword != TRI_NO)
{
+ bool canceled = false;
+
/*
* Prompt for password using the username we actually connected
* with --- it might've come out of "dbname" rather than "user".
*/
- password = prompt_for_password(PQuser(n_conn));
+ password = prompt_for_password(PQuser(n_conn), &canceled);
PQfinish(n_conn);
n_conn = NULL;
+ success = !canceled;
continue;
}