casaroli opened a new pull request, #21414: URL: https://github.com/apache/nuttx/pull/21414
## Summary A telnet client sends a new window size with the NAWS option (RFC 1073). The telnet driver kept the new size for TIOCGWINSZ, but it did not send SIGWINCH to the foreground process, so a full screen program did not see the change. POSIX requires SIGWINCH when the terminal size changes. The driver also did not support TIOCSWINSZ, its TIOCGWINSZ wrote through a NULL argument, and TIOCGWINSZ did not set ws_xpixel and ws_ypixel. This PR fixes the four gaps in drivers/net/telnet.c (all under CONFIG_TELNET_SUPPORT_NAWS): - The driver keeps a struct winsize. TIOCGWINSZ copies all of it; a NAWS size has no pixel values, so they are 0. - TIOCSWINSZ sets the size. - A new size from the client or from TIOCSWINSZ sends SIGWINCH to the PID that TIOCSCTTY gave (CONFIG_TTY_SIGINT or CONFIG_TTY_SIGTSTP), as the driver does for SIGINT and SIGTSTP. The same size again sends no signal. - TIOCGWINSZ and TIOCSWINSZ return -EINVAL for a NULL argument. The driver sends SIGWINCH for a NAWS size after telnet_receive() and before it waits for more data. In a flat build the handler runs at once and can read from the session. In a protected or kernel build the signal ends the wait of the reader with EINTR, as on other systems. A SIGWINCH without a handler is ignored and does not end the read. The second commit updates the NAWS paragraph of Documentation/applications/netutils/telnetd. ## Impact Only builds with CONFIG_TELNET_SUPPORT_NAWS change; no defconfig enables it. The session structure grows by about 10 bytes. SIGWINCH is ignored by default, so programs without a handler see no change. TIOCSWINSZ on a telnet session now works instead of going to the socket ioctl. ## Testing Test program telnetwinsz.c: it opens a telnet session over loopback (SIOCTELNET on /dev/telnet), makes itself the foreground process with TIOCSCTTY, acts as the client and sends IAC SB NAWS. Cases: new size (TIOCGWINSZ, pixels 0), SIGWINCH, same size (no signal), new size while read() waits, no handler (read() does not end), TIOCSWINSZ (size, pixels, SIGWINCH), same TIOCSWINSZ (no signal), NULL argument. | Run | master | this PR | |---|---|---| | qemu-armv8a:knsh (kernel), arm64 | 5 FAIL (get: pixels not set, signal, blocked, set: ENOTTY, setsame), 2 PASS (same, default); null: kernel panic (write to NULL) | 8/8 PASS; blocked: read() ends with EINTR, then reads the next byte | | qemu-armv8a:nsh (flat), arm64 | same as knsh; null: panic | 8/8 PASS; blocked: the handler runs in read(), read() then returns the next byte | | ostest | knsh: not reached (panic), nsh: 0 | knsh 0, nsh 0, flat 0 | Options for the runs: NET, NET_TCP, NET_IPv4, NET_LOOPBACK, NET_SOCKOPTS, NETDEV_TELNET, TELNET_SUPPORT_NAWS, TTY_SIGINT. The same test passes on Linux and macOS with a pseudo-terminal (there NULL gives EFAULT). Builds with -Werror and TELNET_SUPPORT_NAWS: qemu-armv8a:netnsh (with TTY_SIGINT + TTY_SIGTSTP, without both, and the defconfig without NAWS), rv-virt:knetnsh64 (kernel), rv-virt:pnsh64 + network (protected), rv-virt:netnsh (32-bit flat), stm32f4discovery:netnsh (Cortex-M4), sabre-6quad:netknsh (armv7-a kernel, TTY_SIGTSTP only), esp32-devkitc:wifinsh (xtensa). sim: telnet.c compiles; the macOS host cannot link sim with network. tools/checkpatch.sh -c -u -m -g: pass. No CI configuration enables TELNET_SUPPORT_NAWS, so CI does not compile the changed code; the builds above do. -- 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]
