This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 5c637d9038d7d461883fa8e3f49076ffe4320387 Author: Marco Casaroli <[email protected]> AuthorDate: Tue Nov 3 03:12:50 2026 +0100 sched/signal: Report SIG_DFL for a signal at a default that ignores it. With CONFIG_SIG_DEFAULT, 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[]). sigaction() then returned a NULL handler as the old action, and NULL is SIG_IGN. A program that saves the old action and restores it later set the signal to SIG_IGN. For SIGCHLD, SIG_IGN turns on SA_NOCLDWAIT (XSI), and each later waitpid() failed with ECHILD. tg_sigdefault now has every signal that is at its default action, also when that action is to ignore the signal. A signal with no action attached and not in the set is set to SIG_IGN. sigaction() reports SIG_DFL or SIG_IGN from this. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- sched/signal/sig_action.c | 11 +++++++++-- sched/signal/sig_default.c | 22 +++++++++++----------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/sched/signal/sig_action.c b/sched/signal/sig_action.c index 4c6d345c02a..45381f0906c 100644 --- a/sched/signal/sig_action.c +++ b/sched/signal/sig_action.c @@ -261,7 +261,7 @@ int nxsig_action(int signo, FAR const struct sigaction *act, if (oact != NULL) { #ifdef CONFIG_SIG_DEFAULT - if (nxsig_isdefault(rtcb, signo)) + if (sigact != NULL && nxsig_isdefault(rtcb, signo)) { /* Return SIG_DFL if the default signal is attached */ @@ -282,9 +282,16 @@ int nxsig_action(int signo, FAR const struct sigaction *act, } else { - /* There isn't an old value */ + /* No action attached: the signal is ignored, or it is at a + * default action that ignores it. + */ +#ifdef CONFIG_SIG_DEFAULT + oact->sa_handler = nxsig_isdefault(rtcb, signo) ? + SIG_DFL : SIG_IGN; +#else oact->sa_handler = NULL; +#endif oact->sa_flags = 0; sigemptyset(&oact->sa_mask); } diff --git a/sched/signal/sig_default.c b/sched/signal/sig_default.c index 75f05cbcd1c..5922319851a 100644 --- a/sched/signal/sig_default.c +++ b/sched/signal/sig_default.c @@ -535,17 +535,17 @@ _sa_handler_t nxsig_default(FAR struct tcb_s *tcb, int signo, bool defaction) */ handler = nxsig_default_action(signo); - if (handler != SIG_IGN) - { - /* nxsig_addset() is not atomic (but neither is sigaction()) */ - flags = spin_lock_irqsave(&group->tg_lock); - nxsig_addset(&group->tg_sigdefault, signo); - spin_unlock_irqrestore(&group->tg_lock, flags); - } - } + /* The signal is at its default action, also when that action is to + * ignore it. NOTE that nxsig_addset() is not atomic (but neither is + * sigaction()). + */ - if (handler == SIG_IGN) + flags = spin_lock_irqsave(&group->tg_lock); + nxsig_addset(&group->tg_sigdefault, signo); + spin_unlock_irqrestore(&group->tg_lock, flags); + } + else { /* We are unsetting the default action. NOTE that nxsig_delset() is not * atomic (but neither is sigaction()). @@ -583,9 +583,9 @@ int nxsig_default_initialize(FAR struct tcb_s *tcb) DEBUGASSERT(tcb != NULL && tcb->group != NULL); group = tcb->group; - /* Initialize the set of default signal handlers */ + /* All signals start at their default action */ - sigemptyset(&group->tg_sigdefault); + sigfillset(&group->tg_sigdefault); /* Setup the default action for each signal in g_defactions[] */
