cleanup: extract SkipSignal helper to deduplicate signal skip lists (#40228)

* cleanup: extract SkipSignal helper to deduplicate signal skip lists UtilSaveSignalHandlers and UtilSetSignalHandlers had identical switch statements for skipping non-settable signals. Extract a shared helper to keep the skip list in one place. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * address review: document SkipSignal signals and update function headers Add comments explaining why each signal is skipped (POSIX non-settable, NPTL internal signals 32-34, SIGHUP handled separately). Update UtilSaveSignalHandlers and UtilSetSignalHandlers descriptions to reference SkipSignal() instead of just mentioning SIGHUP. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Ben Hillis committed Apr 17, 2026 at 14:09 UTC 5809787b375492ee3de7801b02697685ac3059eb
1 file changed +30 -19
src/linux/init/util.cpp
+30 -19
@@ -2594,13 +2594,38 @@ int UtilSaveBlockedSignals(const sigset_t& SignalMask)
2594 return sigprocmask(SIG_BLOCK, &SignalMask, &g_originalSignals);
2595 }
2596
2597 +// Returns true for signals that should not be saved/restored:
2598 +// SIGKILL/SIGSTOP — not settable per POSIX.
2599 +// SIGCONT — left at default to allow process resumption.
2600 +// SIGHUP — handled separately by the caller.
2601 +// 32-34 — internal NPTL signals (__SIGRTMIN through __SIGRTMIN+2) reserved
2602 +// by glibc for thread cancellation and other runtime use.
2603 +static bool SkipSignal(unsigned int Signal)
2604 +{
2605 + switch (Signal)
2606 + {
2607 + case SIGKILL:
2608 + case SIGSTOP:
2609 + case SIGCONT:
2610 + case SIGHUP:
2611 + case 32:
2612 + case 33:
2613 + case 34:
2614 + return true;
2615 +
2616 + default:
2617 + return false;
2618 + }
2619 +}
2620 +
2621 int UtilSaveSignalHandlers(struct sigaction* SavedSignalActions)
2622
2623 /*++
2624
2625 Routine Description:
2626
2603 - This routine saves all settable signal handlers except SIGHUP.
2627 + This routine saves all settable signal handlers, skipping signals
2628 + listed in SkipSignal() (non-settable, SIGHUP, and internal NPTL signals).
2629
2630 Arguments:
2631
@@ -2615,15 +2640,8 @@ Return Value:
2640 {
2641 for (unsigned int Index = 1; Index < _NSIG; Index += 1)
2642 {
2618 - switch (Index)
2643 + if (SkipSignal(Index))
2644 {
2620 - case SIGKILL:
2621 - case SIGSTOP:
2622 - case SIGCONT:
2623 - case SIGHUP:
2624 - case 32:
2625 - case 33:
2626 - case 34:
2645 continue;
2646 }
2647
@@ -2642,8 +2660,8 @@ int UtilSetSignalHandlers(struct sigaction* SavedSignalActions, bool Ignore)
2660
2661 Routine Description:
2662
2645 - This routine sets all settable signal handlers except SIGHUP to the given
2646 - handler.
2663 + This routine sets all settable signal handlers to the given handler,
2664 + skipping signals listed in SkipSignal().
2665
2666 Arguments:
2667
@@ -2662,15 +2680,8 @@ Return Value:
2680
2681 for (unsigned int Index = 1; Index < _NSIG; Index += 1)
2682 {
2665 - switch (Index)
2683 + if (SkipSignal(Index))
2684 {
2667 - case SIGKILL:
2668 - case SIGSTOP:
2669 - case SIGCONT:
2670 - case SIGHUP:
2671 - case 32:
2672 - case 33:
2673 - case 34:
2685 continue;
2686 }
2687