casaroli commented on code in PR #21065:
URL: https://github.com/apache/nuttx/pull/21065#discussion_r4398240482
##########
sched/signal/sig_clockwait.c:
##########
@@ -197,6 +197,8 @@ int nxsig_clockwait(int clockid, int flags,
clock_t stop = 0u;
#ifndef CONFIG_DISABLE_ALL_SIGNALS
siginfo_t unbinfo;
+ sigset_t intersection;
+ FAR sigq_t *sigpend;
Review Comment:
nxsig_remove_pendingsignal() returns `FAR sigpendq_t *`, not `FAR sigq_t *`.
The build fails at lines 270 and 276 with -Werror=incompatible-pointer-types
(CI sim-01, msys2).
Fix: declare `FAR sigpendq_t *sigpend;`.
##########
sched/signal/sig_clockwait.c:
##########
@@ -253,6 +255,34 @@ int nxsig_clockwait(int clockid, int flags,
rtcb->sigunbinfo = &unbinfo;
own_unbinfo = true;
}
+
+ /* nxsig_timedwait() publishes sigwaitmask before calling this function.
+ * A matching signal can be queued after that publication but before this
+ * task transitions to TSTATE_WAIT_SIG. Re-check the pending set here while
+ * interrupts are disabled so we do not sleep with a waited-for signal
+ * already pending.
+ */
+
+ intersection = nxsig_pendingset(rtcb);
Review Comment:
This check also runs for nanosleep() and clock_nanosleep(), and there
sigwaitmask can be stale: nxsig_timedwait() does not clear it when
nxsig_clockwait() returns an error (for example -EAGAIN for a zero timeout,
sig_timedwait.c:177-181). A later nanosleep() then removes a blocked pending
signal of that set and returns 0 without a sleep, and the signal is lost.
Fix: do the check only when `!own_unbinfo` (the nxsig_timedwait() caller),
and clear `rtcb->sigwaitmask` before the `return ret` at sig_timedwait.c:180.
--
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]