Repository navigation
sched/signal: Restore the mask of pselect() after its signals are dispatched. - #20720
Merged
Merged
Conversation
…patched. pselect(), ppoll() and sigsuspend() install a temporary signal mask and restore the old one before they return. In a system call, a signal that the temporary mask unblocks is not delivered at once: it goes back on the list of pending signals, to be dispatched at the end of the system call. By then the old mask was restored, so a signal that the old mask blocks stayed pending, and its handler never ran. Every later pselect() found it and returned EINTR at once. For example, a program that blocks SIGCHLD and unblocks it only in pselect() never runs its SIGCHLD handler, and its pselect() loop spins. In a system call, keep the temporary mask and save the old one in the TCB. nxsig_unmask_pendingsignal(), at the end of the system call, dispatches the pending signals with the temporary mask, which queues their actions, and then restores the old mask. Outside a system call the mask is restored at once, as before. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
casaroli
requested review from
GUIDINGLI,
Ouss4,
jerpelea,
pussuw and
xiaoxiang781216
as code owners
October 17, 2026 17:17
|
sigsuspend() runs the handlers of the signals that its mask unblocks before it restores the original mask, also in a system call. The page did not say this, and it listed the restore of the mask as a difference from POSIX, which requires it. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
acassis
approved these changes
Oct 18, 2026
Contributor
|
@xiaoxiang781216 PTAL |
xiaoxiang781216
approved these changes
Oct 22, 2026
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pselect(),ppoll()andsigsuspend()install a temporary signal mask and restore the old one before they return. In a system call, a signal that the temporary mask unblocks is not delivered at once: it goes back on the pending list, to be dispatched at the end of the system call. By then the old mask was restored, so a signal that the old mask blocks stayed pending and its handler never ran; every laterpselect()returnedEINTRat once.In a system call, the temporary mask now stays and the old one is saved in the TCB.
nxsig_unmask_pendingsignal(), at the end of the system call, dispatches the pending signals with the temporary mask and then restores the old mask. Outside a system call the mask is restored at once, as before.A second commit updates
sigsuspend()inDocumentation/reference/user/07_signals.rst: the handlers run before the original mask comes back, and the restore of the mask is no longer listed as a difference from POSIX (POSIX requires it).Impact
Kernel builds (
pselect()etc. as system calls): the handler of a signal unblocked only by the temporary mask now runs once. Flat builds behave as before.Testing
Builds:
qemu-armv8a:nsh,qemu-armv8a:knsh,lm3s6965-ek:qemu-flat.Runtime, QEMU 11 with HVF on an Apple M4:
ostestonqemu-armv8a:knsh(kernel build) andqemu-armv8a:nsh(flat build) ends withostest_main: Exiting with status 0.tools/checkpatch.sh -c -u -m -gpasses.A test program on
qemu-armv8a:knsh: blockSIGUSR1, raise it, then callpselect()three times with an empty mask and a 200 ms timeout.master:
This PR: