Repository navigation
console: Ctrl-C interrupts a program reading the console, Ctrl-D ends the read - #401
Merged
Merged
Conversation
daniel-rossier
force-pushed
the
fix/console-intr
branch
4 times, most recently
from
December 2, 2026 09:24
d1c69c1 to
90c4e63
Compare
… the read A program blocked reading the console could not be stopped: Ctrl-C only cancelled the line, so `cat` printed an empty line and read again, and the shell waiting for it kept the console until a reset. SIGINT was sent only when nobody was reading. Ctrl-C now always sends SIGINT to the foreground process and to the reader, and the read fails with -EINTR when its process does not ignore the signal. The root shell is the exception: it only has its line cancelled, as before, since it must not die. The decision moves to serial_ctrl_c(), shared by the PL011, mini UART and PIO UART drivers. Signals are acted upon on the return from the UART interrupt, so the reader may die before it sees the cancelled read: serial_cleanup() now clears the pending cancel with the lock, or the next reader, the shell, had its first line cancelled. Ctrl-D was stored as an ordinary byte. In canonical mode it now ends the read: the line typed so far is returned without a newline, and 0 on an empty line, which is end of file.
daniel-rossier
force-pushed
the
fix/console-intr
branch
from
December 2, 2026 09:36
90c4e63 to
4edfd41
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tested on QEMU virt64:
cat+ Ctrl-C now exits to the prompt (printed an empty line and kept reading before);xCtrl-D Ctrl-D makes cat printxthen exit (stored 0x04 before); a reader with a SIGINT handler gets read=-1/EINTR; Ctrl-C at the shell prompt still reprompts.