-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
read
builtin doesn't respect ctrl-C
#516
Comments
example: try this to permanently lock your shell:
All commands are builtins, so the window where your ctrl-C has to arrive to stop the loop is reduced to essentially zero. |
This looks to be mighty complicated to fix. |
I've created a fix for this on branch bug-read-ctrlC. I haven't merged it yet so you/everyone can have a look at it and verify I didn't miss anything important. |
Reviewing...It seems simpler than my approach, which was to try to handle it in the big switch statement inside reader_readline...I could not work out exactly whether and how control-C was communicated back as a read character. Cutting the big knot by tweaking the signal handler is attractive. However, there are a few other cases where we want to check for (and clear) the interrupt flag, without causing the reader to exit: wildcard expansions, history search, and possibly more in the future. Look for other calls to reader_interrupted. We should convince ourselves that these don't apply, or ensure that canceling a wildcard expansion doesn't anything else. I'd also suggest calling this property something other than "interruptible." It's closer to reader_exits_when_interrupted. |
I was initially thinking along the same lines as you as well, but studying how interrupts were handled brought me to this simpler approach. Note that - if (!is_interactive_read)
+ if (!is_interactive_read || get_interruptible()) and the addition of AFAIK (i.e. according to grep) the only other client of |
The only call to Other thoughts - we want to make sure that The fact that wildcard expansion in background threads calls reader_interrupted is a serious problem and I'm really glad you noticed it. Please open a new issue for that - thanks! |
Ok, I think I understand the desired behavior better now. As I see it, there are three cases:
|
That matches my understanding too! |
…rupted` and a `reader_reading_interrupted`
Thanks for the comments. I've changed things a bit and I think it handles the different cases of interruption now. Please review. I've named the new function |
Reviewed, looks great! Thanks! |
(please ignore d9d8bfa, the correct one is 9a89da3) |
Like any command,
read
should die if it gets a ctrl-CThe text was updated successfully, but these errors were encountered: