libc: honor POSIX default-ignore disposition for SIGCHLD/SIGURG/SIGWINCH#1457
Open
gburd wants to merge 1 commit into
Open
libc: honor POSIX default-ignore disposition for SIGCHLD/SIGURG/SIGWINCH#1457gburd wants to merge 1 commit into
gburd wants to merge 1 commit into
Conversation
kill() treats any signal with a SIG_DFL disposition as uncaught-and-fatal and powers the VM off. That is wrong for SIGCHLD, SIGURG and SIGWINCH, whose POSIX default disposition is to IGNORE, not to terminate: delivering one of them to a process that installed no handler must be a silent no-op. Before this, e.g. raising SIGCHLD with no handler installed would power off the whole guest. Return success (ignore) for those three in the SIG_DFL branch of kill(). tests/tst-sig-dfl-ignore.cc raises and kill()s each of the three with the default disposition and asserts the process survives. Copyright (C) 2026 Greg Burd
gburd
added a commit
to gburd/osv-1
that referenced
this pull request
Jul 24, 2026
…ndler (postmaster PM_RUN wall) A stock PostgreSQL postmaster hung after crash recovery, never reaching PM_RUN: the startup process exited but SIGCHLD never woke the postmaster to reap it and launch the auxiliary processes. Root cause (gdb on the hung image: fork registry showed the startup child exited=1 but unreaped; the postmaster parked in epoll_wait; signal_actions[SIGCHLD] read SIG_DFL) was two shared-global bugs, both under CONF_fork: 1. OSv keeps one global signal_actions[] for the whole machine, but signal dispositions are per-process. PostgreSQL's startup process (a fork child) resets its inherited SIGCHLD to SIG_DFL during its own signal setup; over the shared table that clobbered the postmaster's reaper handler, so kill(getpid(), SIGCHLD) hit the default (ignore) branch and never ran it. Fix: give each fork-child address space its own copy of signal_actions[], seeded from the parent at fork time and mutated only by that child's sigaction(); kill()-to-process keeps reading the top-level (postmaster) table. Kept on the identity kernel heap, keyed by address_space, like the inherited-fd set and the signal-waiters list. 2. kill() swallowed a signal that was merely sigprocmask-BLOCKED: it treated any thread on the waiters list (populated only by sigprocmask) as a sigwait consumer and skipped the handler. The postmaster blocks SIGCHLD but parks in epoll_wait, not sigwait, so the latch/self-pipe poke never ran. Fix: track threads actually inside sigwait()/sigtimedwait() (thread_sigwaiting); wake_up_signal_waiters() still wakes every blocked waiter but returns a nonzero consumed count only for real sigwait consumers, so kill() runs the handler when nobody is sigwaiting. More POSIX-correct; keeps tst-sigwait / tst-kill green on conf_fork=0 and 1. Also run a process-level signal handler in the top-level app's address space (AS0): the handler thread otherwise inherits the exiting child's dying COW AS, so its writes to app globals (latch flag, self-pipe) would land in the wrong address space. With these, PG reaches "database system is ready to accept connections" (PM_RUN): the postmaster wakes on SIGCHLD, reaps the startup process, and launches the aux processes. Serving a query is still blocked on the separate, pre-existing aux-process wild-indirect-branch COW/preemption wall (pg-preempt-fix.txt WALL cloudius-systems#1), which fires right after PM_RUN. New regression test tst-fork-sigchld-latch mirrors the postmaster: install a SIGCHLD handler that writes a self-pipe, epoll_wait on the read end, fork a child that resets SIGCHLD and exits, assert epoll wakes and waitpid reaps. Reproduces the hang on HEAD; passes with the fix. Relevant to shipping PR cloudius-systems#1457 (fork SIGCHLD handling). All new code #if CONF_fork except the sigwait-consumer discriminator (a strict correctness fix, validated conf_fork=0). Author: Greg Burd
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.
What
kill()treats any signal with aSIG_DFLdisposition as uncaught-and-fatal and powers the VM off. That is wrong for SIGCHLD, SIGURG and SIGWINCH, whose POSIX default disposition is to ignore, not to terminate: delivering one of them to a process that has installed no handler must be a silent no-op.Before this, e.g. raising
SIGCHLDwith no handler installed would power off the whole guest.Fix
Return success (ignore) for those three signals in the
SIG_DFLbranch ofkill(). Every other unhandledSIG_DFLsignal still powers off as before — the guard is narrow.Validation (x86-64 / KVM)
tests/tst-sig-dfl-ignore.cc: raises andkill(getpid(), ...)s each of SIGCHLD/SIGURG/SIGWINCH with the default disposition and asserts the process survives. PASS — the guest does not power off (no "Uncaught signal … Powering off").raise(SIGTERM)with default disposition still powers off (fatal), confirming only the three ignore-default signals are exempted.Standalone, independent of any other change.