Skip to content

libc: honor POSIX default-ignore disposition for SIGCHLD/SIGURG/SIGWINCH#1457

Open
gburd wants to merge 1 commit into
cloudius-systems:masterfrom
gburd:fix/sig-dfl-ignore
Open

libc: honor POSIX default-ignore disposition for SIGCHLD/SIGURG/SIGWINCH#1457
gburd wants to merge 1 commit into
cloudius-systems:masterfrom
gburd:fix/sig-dfl-ignore

Conversation

@gburd

@gburd gburd commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

What

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 has 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.

Fix

Return success (ignore) for those three signals in the SIG_DFL branch of kill(). Every other unhandled SIG_DFL signal still powers off as before — the guard is narrow.

Validation (x86-64 / KVM)

  • New tests/tst-sig-dfl-ignore.cc: raises and kill(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").
  • Regression: raise(SIGTERM) with default disposition still powers off (fatal), confirming only the three ignore-default signals are exempted.

Standalone, independent of any other change.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant