casaroli opened a new pull request, #3953:
URL: https://github.com/apache/nuttx-apps/pull/3953

   ## Summary
   
   A NxInit service with the `console` option gets the console device as stdin, 
stdout and stderr, but the console is not its controlling terminal. So Ctrl-C 
and Ctrl-Z send no signal to the service, and a shell on the console finds no 
foreground process group with `tcgetpgrp()` and turns job control off ("can't 
access tty; job control turned off").
   
   The second commit makes NxInit set the console as the controlling terminal 
of such a service after its start, with `TIOCSCTTY` and the PID of the service, 
as init and getty do on other systems. A console without `TIOCSCTTY` (for 
example without `CONFIG_TTY_SIGINT` and `CONFIG_TTY_SIGTSTP`) is not an error.
   
   The first commit is needed for that, and it also fixes a bug on master. The 
NSH `sh` program makes each foreground command the foreground process of its 
terminal and gives the terminal up after the command, so at its prompt Ctrl-C 
signals nothing. But when sh itself is the foreground process, Ctrl-C at its 
prompt sends `SIGINT` to it, and with `CONFIG_SIG_DEFAULT` the shell ends. This 
occurs on master for an `sh` typed at the NSH prompt, and with the second 
commit it would occur for a console sh service. An interactive sh now gives up 
the controlling terminal at its start. `sh -c` does not change.
   
   
   ## Impact
   
   Services with the `console` option: with `CONFIG_TTY_SIGINT` or 
`CONFIG_TTY_SIGTSTP`, Ctrl-C and Ctrl-Z reach the service, and `tcgetpgrp()` on 
the console gives its PID. No board `init.rc` in the tree uses the `console` 
option. An interactive `sh` is no longer the foreground process at its prompt, 
so Ctrl-C there does not end it.
   
   ## Testing
   
   All tests with NuttX master 5c441693fa8 and nuttx-apps master d40132fba 
(2026-11-01), with this PR rebased on it.
   
   Test program `nxctty.c` on qemu-armv8a:knsh (kernel, QEMU with HVF), with 
NxInit as the program `nxinit` 
(`CONFIG_SYSTEM_NXINIT_RC_FILE_PATH=/system/hb-init.rc`), `CONFIG_TTY_SIGINT` 
and `CONFIG_TTY_SIGTSTP`. The program writes an `init.rc` with one service that 
runs `nxctty probe` with the `console` option, and runs NxInit as a child. The 
probe compares `tcgetpgrp(0)` with its own PID:
   
   | Case | apps master | this PR |
   |---|---|---|
   | the service runs | PASS | PASS |
   | `tcgetpgrp(0)` of the service == its PID | FAIL (service 19, `tcgetpgrp()` 
14: the NSH foreground program) | PASS (19, 19) |
   
   qemu-armv8a:nsh (flat, QEMU with HVF), where NxInit is the init, with 
`CONFIG_TTY_SIGINT`, `CONFIG_SIG_DEFAULT` and the `console` option on the `sh` 
service of the board `init.rc`:
   
   | Case | apps master | second commit only | this PR |
   |---|---|---|---|
   | Ctrl-C at the prompt of the console sh | sh runs on | sh ends, init starts 
a new one | sh runs on |
   | `sh` at the prompt, then Ctrl-C | the second sh ends | - | the second sh 
runs on, `exit` goes back to the first |
   
   With 2 CPUs (qemu-armv8a:nsh_smp), apps master and this PR give the same 
results as with 1 CPU.
   
   ostest exits with status 0 on qemu-armv8a:knsh and qemu-armv8a:nsh, before 
and after.
   
   Build with `CONFIG_SYSTEM_NXINIT`, `CONFIG_TTY_SIGINT` and 
`CONFIG_TTY_SIGTSTP`, each OK and with no new warning: qemu-armv8a:knsh 
(kernel, arm64), rv-virt:knsh64 (kernel, rv64), mps2-an500:knsh (protected, 
armv7-m), rv-virt:pnsh64 (protected, rv64), qemu-armv8a:nsh (flat, arm64; with 
`CONFIG_TTY_SIGINT` only, and without the tty options).
   
   `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]

Reply via email to