zyfeier commented on code in PR #22300:
URL: https://github.com/apache/nuttx/pull/22300#discussion_r4697284947
##########
sched/signal/sig_timedwait.c:
##########
@@ -192,80 +192,78 @@ int nxsig_timedwait(FAR const sigset_t *set, FAR struct
siginfo *info,
leave_critical_section(flags);
ret = nxsig_clockwait(CLOCK_REALTIME, 0, timeout, NULL);
- if (ret < 0)
+ if (ret >= 0)
{
- sigemptyset(&rtcb->sigwaitmask);
- rtcb->sigunbinfo = NULL;
- return ret;
- }
+ flags = enter_critical_section();
- flags = enter_critical_section();
+ /* We are running again, clear the sigwaitmask */
- /* We are running again, clear the sigwaitmask */
-
- sigemptyset(&rtcb->sigwaitmask);
-
- /* When we awaken, the cause will be in the TCB. Get the signal number
- * or timeout) that awakened us.
- */
+ sigemptyset(&rtcb->sigwaitmask);
- if (GOOD_SIGNO(unbinfo.si_signo))
- {
- /* We were awakened by a signal... but is it one of the signals
- * that we were waiting for?
+ /* When we awaken, the cause will be in the TCB.
+ * Get the signal number or timeout that awakened us.
*/
- if (nxsig_ismember(set, unbinfo.si_signo) == 1)
+ if (GOOD_SIGNO(unbinfo.si_signo))
{
- /* Yes.. the return value is the number of the signal that
- * awakened us.
+ /* We were awakened by a signal... but is it one of the
+ * signals that we were waiting for?
*/
- ret = unbinfo.si_signo;
- }
- else
- {
- /* No... then report the EINTR error */
+ if (nxsig_ismember(set, unbinfo.si_signo) == 1)
+ {
+ /* Yes.. the return value is the number of the signal
+ * that awakened us.
+ */
- ret = -EINTR;
- }
- }
- else
- {
- /* Otherwise, we must have been awakened by the timeout or,
- * perhaps, the wait was cancelled.
- */
+ ret = unbinfo.si_signo;
+ }
+ else
+ {
+ /* No... then report the EINTR error */
-#ifdef CONFIG_CANCELLATION_POINTS
- if (unbinfo.si_signo == SIG_CANCEL_TIMEOUT)
- {
- /* The wait was canceled */
-
- ret = -unbinfo.si_errno;
- DEBUGASSERT(ret < 0);
+ ret = -EINTR;
+ }
}
else
-#endif
{
- /* We were awakened by a timeout. Set EAGAIN and return an
- * error.
+ /* Otherwise, we must have been awakened by the timeout or,
+ * perhaps, the wait was cancelled.
*/
- DEBUGASSERT(unbinfo.si_signo == SIG_WAIT_TIMEOUT);
- ret = -EAGAIN;
+#ifdef CONFIG_CANCELLATION_POINTS
+ if (unbinfo.si_signo == SIG_CANCEL_TIMEOUT)
+ {
+ /* The wait was canceled */
+
+ ret = -unbinfo.si_errno;
+ DEBUGASSERT(ret < 0);
+ }
+ else
+#endif
+ {
+ /* We were awakened by a timeout. Set EAGAIN and return
+ * an error.
+ */
+
+ DEBUGASSERT(unbinfo.si_signo == SIG_WAIT_TIMEOUT);
+ ret = -EAGAIN;
+ }
}
- }
- rtcb->sigunbinfo = NULL;
+ rtcb->sigunbinfo = NULL;
- if (info != NULL)
- {
- memcpy(info, &unbinfo, sizeof(struct siginfo));
+ if (info != NULL)
+ {
+ memcpy(info, &unbinfo, sizeof(struct siginfo));
+ }
+
+ leave_critical_section(flags);
+ return ret;
}
}
- leave_critical_section(flags);
-
+ rtcb->sigunbinfo = NULL;
Review Comment:
You are right: on the path where the pending-signal loop already set `ret`,
the function returned with the critical section of line 120 still held. The
early return inside the successful-wait branch is gone now; both paths fall
through to a single `leave_critical_section()` at the end of the wait block,
and the pending path leaves it there as well.
##########
sched/signal/sig_timedwait.c:
##########
@@ -192,80 +192,78 @@ int nxsig_timedwait(FAR const sigset_t *set, FAR struct
siginfo *info,
leave_critical_section(flags);
ret = nxsig_clockwait(CLOCK_REALTIME, 0, timeout, NULL);
- if (ret < 0)
+ if (ret >= 0)
Review Comment:
Fixed: the `nxsig_clockwait()` failure now clears `sigwaitmask` and
`sigunbinfo` in an else branch, as master does, so the mask cannot let an
ignored signal wake a later `nanosleep()`. The token stream of the function
now differs from master only by this else form.
--
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]