casaroli opened a new pull request, #21441: URL: https://github.com/apache/nuttx/pull/21441
## Summary With `CONFIG_SIG_DEFAULT`, `SIG_IGN` is 0 and `SIG_DFL` is 1. No action is attached to a signal whose default action is to ignore it (SIGCHLD, SIGWINCH, SIGURG and the other signals that are not in `g_defactions[]`). So `sigaction(SIGCHLD, NULL, &old)` returned a NULL handler, which is `SIG_IGN`, for a signal at its default. A program that saves the old action and restores it later (also `signal()` and `siginterrupt()`, which call `sigaction()` this way) set the signal to `SIG_IGN`. For SIGCHLD, `SIG_IGN` turns on `SA_NOCLDWAIT` (XSI), and each later `waitpid()` failed with `ECHILD`. - **sched/signal: Report SIG_DFL for a signal at a default that ignores it.** The group records the signals set to `SIG_IGN` (`tg_sigignore`, with `CONFIG_SIG_DEFAULT` only). `nxsig_action()` reports `SIG_IGN` for these signals and `SIG_DFL` for the other signals with no action attached. `fork()` copies the set. `tg_sigdefault` does not change: it means "a default handler is attached", and `nxsig_deliver()` uses it to call that handler in the kernel. - **Documentation: sigaction() reports SIG_DFL for a signal at its default.** `Documentation/reference/user/07_signals.rst`. depends-on: apache/nuttx/pull/21436 ## Impact Only builds with `CONFIG_SIG_DEFAULT`. The old action that `sigaction()` reports for a signal at a default action that ignores it is now `SIG_DFL` (before: `SIG_IGN`), as POSIX says. `signal()` returns `SIG_DFL` for such a signal. The action itself does not change: the signal is still ignored. `SA_NOCLDWAIT` is still reported and restored as before. One `sigset_t` more in `struct task_group_s`. All build modes and architectures (common code). This changes a result that programs see, also in the flat build: the old handler of SIGCHLD, SIGWINCH, SIGURG and the other ignored-by-default signals. ## Testing Test program `sigchlddfl`. QEMU with HVF, `CONFIG_SIG_DEFAULT` and `CONFIG_SCHED_CHILD_STATUS`; the flat build also with `CONFIG_CANCELLATION_POINTS`. The results are the same on qemu-armv8a:knsh (kernel) and qemu-armv8a:nsh (flat): | Case | master | this PR | |---|---|---| | old action of SIGCHLD, SIGWINCH, SIGURG (want `SIG_DFL`) | `SIG_IGN`: FAIL | `SIG_DFL`: PASS | | old action of SIGTERM (attached default, want `SIG_DFL`) | PASS | PASS | | save and restore SIGCHLD, then `waitpid()` of a child that exits with 7 | `ECHILD`: FAIL | 7: PASS | | SIGWINCH set to `SIG_IGN`, then `SIG_DFL`: reported as set | `SIG_IGN`, `SIG_IGN`: FAIL | `SIG_IGN`, `SIG_DFL`: PASS | | SIGCHLD set to `SIG_IGN`, then `SIG_DFL`: reported as set; then `waitpid()` | `SIG_IGN`, `SIG_IGN`: FAIL; `waitpid()` PASS | PASS | | SIGCHLD `SIG_DFL` + `SA_NOCLDWAIT`: reported, kept by a save and restore, cleared by the restore of the first action, then `waitpid()` | FAIL | PASS | ostest: qemu-armv8a:knsh 0 and qemu-armv8a:nsh 0, on master and with this PR. Build with `EXTRAFLAGS="-Wno-cpp -Werror"` as CI, each OK: qemu-armv8a:nsh (flat, without `CONFIG_SIG_DEFAULT`; and with `CONFIG_SIG_DEFAULT` and `CONFIG_CANCELLATION_POINTS`), qemu-armv8a:knsh (kernel), rv-virt:citest (flat, rv32), rv-virt:ksmp64 (kernel, SMP, rv64) and mps2-an500:knsh (protected, Cortex-M7), all with `CONFIG_SIG_DEFAULT`. `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]
