make the read builtin respect ctrl-C

This commit is contained in:
Jan Kanis 2013-01-20 23:35:41 +01:00
parent abae08a9fb
commit 970d05df39
2 changed files with 15 additions and 1 deletions

View File

@ -2399,6 +2399,7 @@ static int builtin_read(parser_t &parser, wchar_t **argv)
}
/* No autosuggestions in builtin_read */
reader_set_allow_autosuggesting(false);
reader_set_interruptible(true);
reader_set_buffer(commandline, wcslen(commandline));
proc_push_interactive(1);

View File

@ -580,10 +580,23 @@ static void reader_kill(size_t begin_idx, size_t length, int mode, int newv)
}
/*
Called from a signal handler, so make sure to check \c data exists.
This is in fact racey as there is no guarantee that \c *data's members are
written to memory before \c data is. But signal handling is currently racey
anyway, so this should be fixed together with the rest of the signal
handling infrastructure.
*/
static bool get_interruptible()
{
return data ? data->interruptible : false;
}
/* This is called from a signal handler! */
void reader_handle_int(int sig)
{
if (!is_interactive_read)
if (!is_interactive_read || get_interruptible())
{
parser_t::skip_all_blocks();
}