Repository navigation
drivers/serial, sched/signal: Discard Ctrl-C and Ctrl-Z; fix kill() to a process group. - #21144
Merged
Merged
Conversation
|
casaroli
force-pushed
the
g9-console-up
branch
from
October 30, 2026 07:38
95e9e75 to
ad220f7
Compare
casaroli
requested review from
masayuki2009,
pkarashchenko and
yamt
as code owners
October 30, 2026 07:38
casaroli
force-pushed
the
g9-console-up
branch
from
November 1, 2026 09:09
ad220f7 to
757ad8d
Compare
casaroli
force-pushed
the
g9-console-up
branch
from
November 1, 2026 10:50
757ad8d to
054f14c
Compare
casaroli
marked this pull request as draft
November 1, 2026 11:28
casaroli
marked this pull request as ready for review
November 1, 2026 11:28
When ISIG is set and the terminal knows its foreground process, the INTR (Ctrl-C) and SUSP (Ctrl-Z) characters send SIGINT and SIGTSTP. The driver also put the character into the receive buffer, so the next read() gave it to the program: after Ctrl-C a shell got "^C" in front of the next command line. POSIX says that the terminal discards such a character when it processes it. Now uart_check_special() removes every special character that it acts on: INTR and SUSP when they send a signal, and the LAUNCH and FORCE_PANIC characters. Its size argument is now in and out: it returns the number of characters that are left. All receive paths use it: receive(), recvbuf() and the DMA path, where the characters that are left in the second region move to follow the first region. A character that sends no signal (no foreground process, or ISIG not set) stays as before. uart_check_special() now handles every character of the batch, not only the ones before the first special character, and returns the signal of the first INTR or SUSP character. uart_recvchars() keeps the first signal of a batch: the check of each later character set it back to 0, so a Ctrl-C with more characters in the same interrupt sent no signal. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
The serial driver no longer passes on the INTR and SUSP characters that send SIGINT and SIGTSTP. Say it in the job control paragraph. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
kill() failed with ENOSYS for a negative pid (a process group), and for pid 0 (the process group of the caller) it sent the signal to the idle task. In NuttX a process group is one process: getpgid() and setpgid() use the process ID as the group ID, and killpg() already sends the signal to that process. A shell with job control sends "kill %1" to the process group of the job and failed. Now pid 0 is the caller and -pid is the process pid, as killpg() does. pid -1 (all processes) still fails with ENOSYS. Some functions used kill(pid, 0) to find a process, and a negative pid failed there. So that it still fails: clock_getcpuclockid() and setpgid() (ESRCH) reject a negative pid, and waitpid() and waitid() look for the child with nxsched_get_tcb(), which is what kill(pid, 0) did. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
The kill() reference and the serial driver page said that kill() to a process group is not supported. It now sends the signal to the one process of the group. pid -1 (all processes) still gives ENOSYS. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
casaroli
force-pushed
the
g9-console-up
branch
from
November 1, 2026 14:18
054f14c to
c688026
Compare
xiaoxiang781216
approved these changes
Nov 1, 2026
casaroli
marked this pull request as draft
November 1, 2026 18:58
casaroli
marked this pull request as ready for review
November 1, 2026 18:58
acassis
approved these changes
Nov 1, 2026
This was referenced Nov 2, 2026
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.
Summary
This PR fixes two parts of job control on a console: the Ctrl-C and Ctrl-Z characters that send a signal, and
kill()to a process group.ISIGis set and the terminal knows its foreground process, INTR (Ctrl-C) and SUSP (Ctrl-Z) sendSIGINTandSIGTSTP. The serial driver also put the character into the receive buffer, so the nextread()gave it to the program: after Ctrl-C, a shell read^Cin front of the next command line. POSIX (General Terminal Interface, 11.1.9 "Special Characters") says that the terminal discards these characters whenISIGis set; the pty and telnet drivers already do. Nowuart_check_special()removes every special character that it acts on: INTR and SUSP when they send a signal, and theCONFIG_TTY_LAUNCHandCONFIG_TTY_FORCE_PANICcharacters. Its size argument is now in and out (the number of characters that are left). All receive paths use it:receive(),recvbuf()and the DMA path (uart_recvchars_done(): sim withCONFIG_SIM_UART_DMA, virtio-serial, CDC/ACM, 16550 RX DMA, rpmsg), where the characters that are left in the second region move to follow the first region. A character that sends no signal (no foreground process, orISIGnot set) stays in the data.uart_check_special()now handles every character of a batch (before: only up to the first special character) and returns the signal of the first INTR or SUSP;uart_recvchars()keeps the first signal of a batch: the check of each later character set the signal back to 0, so Ctrl-C followed by more characters in the same interrupt sent no signal.serial.rst.kill()failed withENOSYSfor a negative pid (a process group), and pid 0 (the process group of the caller) sent the signal to the idle task. In NuttX a process group is one process:getpgid()andsetpgid()use the process ID as the group ID, andkillpg()already sends the signal to that process. Now pid 0 is the caller and -pid is the process pid; pid -1 (all processes) still fails withENOSYS. A shell with job control sendskill %1to the process group of the job.clock_getcpuclockid(),setpgid(),waitpid()andwaitid()usedkill(pid, 0)to find a process; they now reject a negative pid themselves, so their result does not change (setpgid()givesESRCH, before:ENOSYS).kill()reference andserial.rstsaid that a signal to a process group is not supported.Impact
Behaviour change, every build mode (flat too):
CONFIG_TTY_SIGINTorCONFIG_TTY_SIGTSTPand a foreground process: the program no longer reads the Ctrl-C or Ctrl-Z character that sent the signal. WithISIGset, the program also no longer reads theCONFIG_TTY_LAUNCHandCONFIG_TTY_FORCE_PANICcharacters. Without a foreground process nothing changes: NSH sets the foreground process only while a foreground command runs (TIOCSCTTY, thenTIOCNOTTY), so at the NSH prompt the readline editor still gets Ctrl-C.uart_check_special()(include/nuttx/serial/serial.h) now takes the size as a pointer (in and out) and changes the buffer; only drivers/serial calls it.kill(0, sig)now signals the caller (before: the idle task).kill(-pid, sig)now signals process pid (before:ENOSYS); a group that does not exist givesESRCH(before:ENOSYS).kill(-1, sig)still fails withENOSYS.In-tree users, nuttx and nuttx-apps master:
examples/nanoxtermcallskill(-pid, SIGHUP); it now reaches the child. NSH'skillcommand accepts only a pid >= 0, sokill -9 0now signals NSH itself (before: the idle task). All otherkill()andnxsig_kill()callers pass a pid > 0 (a child, a daemon, the foreground PID of a terminal). The only ^C reader in nuttx-apps,system/readline(Ctrl-C cancels a Ctrl-R search), runs at the NSH prompt.Testing
Tested on master 3122150 and on this PR rebased on it (again after the review changes, on master c7bde63), with QEMU (HVF),
CONFIG_TTY_SIGINT,CONFIG_TTY_SIGTSTPandCONFIG_SIG_DEFAULT:qemu-armv8a:knsh(kernel build, programs on v9fs) andqemu-armv8a:nsh(flat build, the programs as NSH built-ins on the serial console).isigtest.ccatchesSIGINTand reads a line from the console; the test types Ctrl-C, thenabcand Enter. The same result in the kernel and the flat build:SIGINTread()gives03 61 62 63 0a(the Ctrl-C first): FAIL61 62 63 0a: PASSkillpgrp.c; the child is the program itself, started withposix_spawn(). The same result in the kernel and the flat build:getpgid(child) == childkill(-child, SIGTERM)ENOSYS: FAILwaitpid())kill(0, SIGUSR1)runs the handler of the callerkill(0, 0)kill(-1, 0)ENOSYS: PASSENOSYS: PASSkill(-30000, 0)(no such group)ENOSYS: FAILESRCH: PASSclock_getcpuclockid(-2)and(-getpid())setpgid(-getpid(), 0)ENOSYS: FAILESRCH: PASSwaitpid(-getpid(), WNOHANG)withSA_NOCLDWAITECHILD: PASSECHILD: PASSwaitid(P_PID, -getpid(), WNOHANG)withSA_NOCLDWAITECHILD: PASSECHILD: PASSThe LTP test
ltp_interfaces_clock_getcpuclockid_6_1(its source run onqemu-armv8a:knshand:nsh): PASS.ostest exits with status 0 on
qemu-armv8a:knshandqemu-armv8a:nsh, on master and with this PR.A host test builds
uart_check_special()and the DMA-path function from the source with stubs: INTR/SUSP removed and the first signal kept, the launch and panic characters removed (panic at the repeat count), no change without a foreground PID, with_POSIX_VDISABLEor withoutISIG, and DMA data in one region and in two regions (characters removed in either, all, or none): 21/21 PASS.Builds, each OK and without new warnings:
lm3s6965-ek:nsh(flat, Cortex-M3) withCONFIG_SERIAL_TERMIOS,CONFIG_TTY_SIGINTandCONFIG_TTY_SIGTSTP;lm3s6965-ek:qemu-protected(protected, Cortex-M3);rv-virt:pnsh64(protected, RISC-V) andrv-virt:knsh64(kernel, RISC-V) withCONFIG_SERIAL_TERMIOS,CONFIG_TTY_SIGINTandCONFIG_TTY_SIGTSTP;qemu-armv8a:nshwith each ofCONFIG_TTY_SIGINT,CONFIG_TTY_SIGTSTP,CONFIG_TTY_FORCE_PANIC,CONFIG_TTY_LAUNCHalone, none of them, and all of them with the DMA receive path (CONFIG_DRIVERS_VIRTIO_SERIAL);sim:nshwithCONFIG_SIM_UART_DMA(macOS host).lm3s6965-ek:qemu-protectedoverflows its kernel flash with the local GCC 13.2 on master too (288 bytes; this PR: 320).tools/checkpatch.sh -c -u -m -gpasses.