casaroli opened a new pull request, #21795: URL: https://github.com/apache/nuttx/pull/21795
depends-on: apache/nuttx/pull/21778 ## Summary `TIOCGWINSZ` and `TIOCSWINSZ` worked only on the telnet driver. The serial driver and the pseudo-terminal driver returned `ENOTTY`, so a program could not get the terminal size, `tcgetwinsize()` failed on a serial console, and `openpty()` could not set the size. This PR: - keeps a `struct winsize` in each serial device (`struct uart_dev_s`); - keeps one size for the two ends of a pseudo-terminal, because the size belongs to the terminal, not to one end; - sends `SIGWINCH` to the foreground PID when the size changes (for a pseudo-terminal: the foreground PID of the slave), if `CONFIG_TTY_SIGINT` or `CONFIG_TTY_SIGTSTP` keeps 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 inside `nxsig_kill()`, and a handler usually calls `TIOCGWINSZ` again. 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_s` and the pseudo-terminal device pair get a `struct winsize` (8 bytes each). No new option. No change for programs that do not use the ioctls; `SIGWINCH` has no default action, so a program without a handler ignores it. All build modes: the drivers read and write the `struct winsize` of the caller as they do for `TCGETS` and `TCSETS`. ## Testing Test program `winsize.c` (the `SIGWINCH` handler reads the size again with `TIOCGWINSZ` on the same terminal), with `CONFIG_PSEUDOTERM`, `CONFIG_PSEUDOTERM_SUSV1`, `CONFIG_SERIAL_TERMIOS`, `CONFIG_TTY_SIGINT`, `CONFIG_TTY_SIGTSTP` and `CONFIG_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: | Case | master (knsh and nsh) | this PR (knsh and nsh) | |---|---|---| | serial console: set + get, 1 `SIGWINCH`, the handler sees the new size | `ENOTTY` | PASS | | serial console: the same size again, no `SIGWINCH` | not run (`ENOTTY` above) | PASS | | `openpty()` size, read on the slave | `ENOTTY` | 24x80, PASS | | the same size on the master | `ENOTTY` | 24x80, PASS | | `TIOCSWINSZ` on the master: the slave sees it, 1 `SIGWINCH`, the handler sees the new size | `ENOTTY` | PASS | | the same size again: no `SIGWINCH` | `ENOTTY` | PASS | | `TIOCSWINSZ` on the slave: the master sees it, 1 `SIGWINCH`, the handler sees the new size | `ENOTTY` | PASS | | `SIGWINCH` with the default action: the program goes on | `ENOTTY` | PASS | | (knsh) a `fork()` child is the foreground process of the slave: `TIOCSWINSZ` on the master in the parent sends it `SIGWINCH` | FAIL | PASS | ostest 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, with `CONFIG_PSEUDOTERM` but without `CONFIG_TTY_SIGINT`, `CONFIG_TTY_SIGTSTP` and `CONFIG_SERIAL_TERMIOS`, and with `CONFIG_TTY_SIGTSTP` only; qemu-armv8a:knsh (kernel, arm64) without the options and with them but without `CONFIG_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 -g` passes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
