Skip to content

console: Ctrl-C interrupts a program reading the console, Ctrl-D ends the read - #401

Merged
daniel-rossier merged 1 commit into
mainfrom
fix/console-intr
Dec 2, 2026
Merged

daniel-rossier merged 1 commit into
mainfrom
fix/console-intr

Conversation

@daniel-rossier

Copy link
Copy Markdown
Contributor
  • Ctrl-C sends SIGINT to the foreground process and to the console reader even while a read is in progress; the read fails with -EINTR unless SIGINT is ignored. The root shell still only has its line cancelled.
  • The Ctrl-C decision is shared in serial_ctrl_c() (PL011, mini UART, PIO UART).
  • serial_cleanup() clears a pending cancel when the reader dies, so it does not cancel the shell's next line.
  • Ctrl-D in canonical mode ends the read: the pending line without newline, or 0 on an empty line.

Tested on QEMU virt64: cat + Ctrl-C now exits to the prompt (printed an empty line and kept reading before); x Ctrl-D Ctrl-D makes cat print x then exit (stored 0x04 before); a reader with a SIGINT handler gets read=-1/EINTR; Ctrl-C at the shell prompt still reprompts.

@daniel-rossier
daniel-rossier force-pushed the fix/console-intr branch 4 times, most recently from d1c69c1 to 90c4e63 Compare December 2, 2026 09:24
… 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
daniel-rossier merged commit bc9db87 into main Dec 2, 2026
6 checks passed
@daniel-rossier
daniel-rossier deleted the fix/console-intr branch December 2, 2026 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant