casaroli opened a new pull request, #21153: URL: https://github.com/apache/nuttx/pull/21153
## Summary Four fixes of the terminal interface. Programs that read or set the special characters of a terminal, or that set a pseudo-terminal through its master, did not compile or did not work. 1. **include/termios.h: Make c_cc large enough for every index.** `VLNEXT` (15) and `VEOL2` (16) were defined, but `NCCS` was 12: a program that set `c_cc[VLNEXT]` or `c_cc[VEOL2]` wrote past the end of the array, into `c_speed` or the padding before it. `NCCS` is now 17. The indexes `VREPRINT`, `VDISCARD`, `VWERASE` and the local mode `ECHOPRT` are added with the values of Linux (the other indexes and flags of NuttX already have them). 2. **drivers/serial, drivers/net/telnet: Give the special characters in c_cc.** `TCGETS` of a serial port, a pty and a telnet session set only `c_cc[VMIN]` and `c_cc[VTIME]` (serial) or nothing, so `tcgetattr()` returned what the caller had in its buffer for the other entries. Now `TCGETS` gives every entry: INTR and SUSP (`CONFIG_TTY_SIGINT_CHAR` and `CONFIG_TTY_SIGTSTP_CHAR` at the start), ERASE (DEL) on a serial port, MIN and TIME, and `_POSIX_VDISABLE` for the characters that the terminal does not act on. `TCSETS` sets INTR and SUSP, and `_POSIX_VDISABLE` disables them. A pty pair keeps one set for both ends. `<unistd.h>` now defines `_POSIX_VDISABLE` (`'\0'`, as Linux), which POSIX requires, and `fpathconf(_PC_VDISABLE)` returns it. 3. **drivers/serial/pty: Set the terminal of the slave also through the master.** `TCGETS` and `TCSETS` of a pty read and set the flags of the end they are called on, and the master echoed when a program set `ECHO` through it. On other systems the termios of a pty belong to the terminal, the slave, also through the master, and the master does no echo. A program that copies the termios of its own terminal to the master and runs a child on the slave got the child's output echoed back into the child's input: when the child did not read it, the pipes filled and both ends waited for each other. Now `TCGETS` and `TCSETS` use the slave's flags on both ends; the master keeps its own flags, which do no echo. 4. **include/nuttx/serial/tioctl.h: Remove TIOCGSERIAL and TIOCSSERIAL.** No driver handles them, and NuttX has no `struct serial_struct`, their argument. A program that uses them when they are defined did not compile. Without the definitions it leaves that code out, as on a system that does not have them. ## Impact - `NCCS` goes from 12 to 17, so `sizeof(struct termios)` changes. Programs that use `struct termios` (`tcgetattr()`, `tcsetattr()`, `cfmakeraw()` ...) must be built again. In nuttx and nuttx-apps, `c_cc` is used only by name (`VMIN`, `VTIME`) and `NCCS` only in `include/termios.h`. - `TIOCGSERIAL` and `TIOCSSERIAL` are removed from a public header. No code in nuttx or nuttx-apps uses them. - `tcsetattr()` now takes INTR and SUSP from `c_cc`. A program that fills a `struct termios` from zeros (instead of `tcgetattr()` first) disables these characters, as on other systems. Every file in nuttx-apps that calls `tcsetattr()` also calls `tcgetattr()`; in nuttx, `openpty()` passes the caller's `struct termios`. - `tcgetattr()` and `tcsetattr()` on a pty master act on the slave's termios. No code in nuttx or nuttx-apps sets termios on a master (`openpty()` sets the slave). - ERASE is given but cannot be changed (the serial driver erases with DEL and BS). - Documentation: `posix.rst` lists `_POSIX_VDISABLE` as supported; the help of `TTY_SIGINT_CHAR` and `TTY_SIGTSTP_CHAR` says that `tcsetattr()` can change them. ## Testing Test programs: `termcc.c` (`c_cc`; with the argument `keys` the rig types Ctrl-C and Ctrl-G on the console), `ptytermios.c` (the termios of a pty through the master), `ptychild.c` (a parent copies its terminal's termios to the master and reads a child's output and status lines; the child writes on the slave), `tiocgserial.c` (uses `struct serial_struct` when `TIOCGSERIAL` is defined). | Test, case | master | this PR | |---|---|---| | `termcc`: `size`, `vdisable`, `tty-get`, `pty-get`, `pty-pair`, `pty-intr`, `pty-off` | does not compile | all 7 PASS (kernel and flat) | | `termcc keys`: `tty-off` (INTR disabled: Ctrl-C is data), `tty-new` (INTR = Ctrl-G sends SIGINT) | does not compile | both PASS (kernel and flat) | | `ptytermios`: `shared`, `noecho`, `echo` | all 3 FAIL (kernel and flat) | all 3 PASS (kernel and flat) | | `ptychild`: `output`, `status`, `ended` | 256 bytes, then both wait: FAIL | 1490 bytes, 670 status bytes, the child is reaped: PASS | | `tiocgserial`: `defined`, `ioctl` | does not compile | PASS (kernel and flat) | | Build | Config (QEMU, HVF; with `PSEUDOTERM`, `PSEUDOTERM_SUSV1`, `PIPES`, `TTY_SIGINT`, `TTY_SIGTSTP`) | master (192ac6d3fbc) | this PR | |---|---|---|---| | kernel, arm64 | `qemu-armv8a:knsh` | `termcc`, `tiocgserial` do not compile; `ptytermios`, `ptychild` FAIL; ostest 0 | all PASS; ostest 0 | | flat, arm64 | `qemu-armv8a:nsh` (the tests as builtin apps; `ptychild` needs `fork()`) | `ptytermios` FAIL; ostest 0 (`termcc`, `tiocgserial` not built) | `termcc` (with `keys`), `tiocgserial`, `ptytermios`: all PASS; ostest 0 | ostest also exits with status 0 on `qemu-armv8a:nsh` (the flat build of the kernel run). Builds (make): `nucleo-f072rb:nsh` (flat, armv6-m), `lm3s6965-ek:qemu-protected` (protected, armv7-m), `rv-virt:knsh64` (kernel, risc-v), `rv-virt:pnsh64` + `PSEUDOTERM`, `TTY_SIGINT`, `TTY_SIGTSTP` (protected, risc-v), `clicker2-stm32:mrf24j40-starhub` + `TTY_SIGINT`, `TTY_SIGTSTP` (telnet driver, armv7-m), `qemu-armv8a:nsh` + `SERIAL_TERMIOS`, `PSEUDOTERM`, `TTY_SIGINT`, `TTY_SIGTSTP`: OK. The QEMU runs above are without `SERIAL_TERMIOS`. `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]
