Repository navigation
drivers/serial: Support TIOCGWINSZ and TIOCSWINSZ - #21795
Merged
Merged
Conversation
The serial and pseudo-terminal drivers returned ENOTTY for TIOCGWINSZ and TIOCSWINSZ, so programs could not get the terminal size, and openpty() could not set it. The serial upper half keeps a struct winsize per device. The PTY keeps one size for the master and the slave, as the size belongs to the terminal and not to one end. The size is 0x0 until a program sets it. A change of the size sends SIGWINCH to the foreground PID (the slave's for a PTY) when CONFIG_TTY_SIGINT or CONFIG_TTY_SIGTSTP keeps that PID. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
Describe TIOCGWINSZ, TIOCSWINSZ and SIGWINCH for the serial and pseudo-terminal drivers. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
casaroli
requested review from
Donny9,
GUIDINGLI,
jerpelea and
xiaoxiang781216
as code owners
November 12, 2026 12:21
acassis
approved these changes
Nov 12, 2026
casaroli
marked this pull request as draft
November 12, 2026 14:08
casaroli
marked this pull request as ready for review
November 12, 2026 14:08
xiaoxiang781216
approved these changes
Nov 12, 2026
🔗 Cross-repo PR dependenciesThe read-only Build run reported the following dependent PR(s) and fetched head SHA(s): |
|
🔗 Cross-repo PR dependenciesThe read-only Build run reported the following dependent PR(s) and fetched head SHA(s): |
1 task done
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.
depends-on: /pull/21778
depends-on: /pull/21800
Summary
TIOCGWINSZandTIOCSWINSZworked only on the telnet driver. The serial driver and the pseudo-terminal driver returnedENOTTY, so a program could not get the terminal size,tcgetwinsize()failed on a serial console, andopenpty()could not set the size.This PR:
struct winsizein each serial device (struct uart_dev_s);SIGWINCHto the foreground PID when the size changes (for a pseudo-terminal: the foreground PID of the slave), ifCONFIG_TTY_SIGINTorCONFIG_TTY_SIGTSTPkeeps that PID. The same size again sends no signal. The pseudo-terminal sends the signal after it releases its lock: in a flat build the signal handler of the caller runs insidenxsig_kill(), and a handler usually callsTIOCGWINSZagain.The size is 0 rows and 0 columns until a program sets it. The second commit describes the ioctls in
Documentation/os/drivers/character/serial.rst.Impact
New ioctls on serial and pseudo-terminal devices.
struct uart_dev_sand the pseudo-terminal device pair get astruct winsize(8 bytes each). No new option. No change for programs that do not use the ioctls;SIGWINCHhas no default action, so a program without a handler ignores it. All build modes: the drivers read and write thestruct winsizeof the caller as they do forTCGETSandTCSETS.Testing
Test program
winsize.c(theSIGWINCHhandler reads the size again withTIOCGWINSZon the same terminal), withCONFIG_PSEUDOTERM,CONFIG_PSEUDOTERM_SUSV1,CONFIG_SERIAL_TERMIOS,CONFIG_TTY_SIGINT,CONFIG_TTY_SIGTSTPandCONFIG_SIG_DEFAULT, on qemu-armv8a:knsh (kernel build, the program from/system/bin) and qemu-armv8a:nsh (flat build, the program as a builtin), QEMU with HVF:SIGWINCH, the handler sees the new sizeENOTTYSIGWINCHENOTTYabove)openpty()size, read on the slaveENOTTYENOTTYTIOCSWINSZon the master: the slave sees it, 1SIGWINCH, the handler sees the new sizeENOTTYSIGWINCHENOTTYTIOCSWINSZon the slave: the master sees it, 1SIGWINCH, the handler sees the new sizeENOTTYSIGWINCHwith the default action: the program goes onENOTTYfork()child is the foreground process of the slave:TIOCSWINSZon the master in the parent sends itSIGWINCHostest exits with status 0 on qemu-armv8a:knsh and qemu-armv8a:nsh with these options, on master and with this PR.
Builds with
-Werror, each OK: qemu-armv8a:nsh (flat, arm64) without the options, with all of them, withCONFIG_PSEUDOTERMbut withoutCONFIG_TTY_SIGINT,CONFIG_TTY_SIGTSTPandCONFIG_SERIAL_TERMIOS, and withCONFIG_TTY_SIGTSTPonly; qemu-armv8a:knsh (kernel, arm64) without the options and with them but withoutCONFIG_SERIAL_TERMIOS; with all the options: mps2-an500:knsh (protected, Cortex-M7), rv-virt:pnsh64 (protected, rv64), rv-virt:knsh64 (kernel, rv64), sim:nsh and esp32s3-devkit:nsh (Xtensa). lm3s6965-ek:qemu-protected builds as it is; with the options its kernel flash overflows on master too (by 5984 bytes; 6200 with this PR).tools/checkpatch.sh -c -u -m -gpasses.