Skip to content

Guard the screensaver exit handler against signal re-entry - #16820

Closed
AnPod wants to merge 2 commits into
omacom:quattrofrom
AnPod:screensaver-exit-trap-guard
Closed

AnPod wants to merge 2 commits into
omacom:quattrofrom
AnPod:screensaver-exit-trap-guard

Conversation

@AnPod

@AnPod AnPod commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #16807

Problem

omarchy-screensaver can die with SIGSEGV while being dismissed. The reporter's core shows a stack overflow: exit_screensaver nested ~4,800 deep, every level handling a SIGHUP.

exit_screensaver is the trap handler for SIGINT/SIGTERM/SIGHUP/SIGQUIT and neither disables those traps nor guards against re-entry. Since bash 5.3, pending traps run between commands inside a running trap handler, so every signal that arrives before exit 0 starts a nested exit_screensaver. During a burst (monitor churn, PipeWire restart, or the handler's own pkill taking down its terminal), the nesting runs away until the stack probe faults.

Fix

bin/omarchy-screensaver: the first statement of exit_screensaver now ignores the exit signals (trap '' SIGINT SIGTERM SIGHUP SIGQUIT), so any burst of signals still ends in the one clean exit already in progress.

Test

A new case in test/shell.d/screensaver-workspace-test.sh runs the real script with stubbed hyprctl/ttfx/pgrep, where the handler's own hyprctl call sends the script a SIGHUP mid-handler — the feedback path from the report.

  • Without the fix the run dies with SIGSEGV (exit 139) from the recursion — verified red on clean quattro.
  • With the fix it exits 0 with the handler's restore call executed exactly once.

The existing screensaver/idle tests (idle-test.sh, screensaver-workspace-test.sh, shell-idle-spawn-test.sh) still pass.

bash 5.3 runs pending traps between commands inside a running trap
handler, so a SIGHUP arriving while exit_screensaver runs re-entered it
from inside itself once per further signal, recursing until the stack
overflowed (seen as a SIGSEGV mid-dismiss, 4,800 nested handler frames
in the core). Ignore the exit signals at the top of the handler so any
burst still ends in a single clean exit.

Fixes omacom#16807
@greptile-apps

greptile-apps Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge, with no outstanding findings.

Summary

exit_screensaver now ignores further exit signals before restoring the cursor and stopping screensaver processes.

  • The screensaver ignores new exit signals while it cleans up.

Reviews (2) · Last reviewed commit: "Fold the screensaver SIGHUP re-entry tes..." · Reviewed by Greptile

The re-entry case lived in its own file with a separate stub setup; it
now runs as the last section of screensaver-workspace-test.sh, reusing
that file's stubs and assertion style so screensaver coverage stays in
one file.
@omarchybot omarchybot added the bug Something isn't working label Nov 2, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

This makes the same change as #9042 by @PyRo1121, opened on August 30 and still open: both add trap '' SIGINT SIGTERM SIGHUP SIGQUIT as the first statement of exit_screensaver in bin/omarchy-screensaver, against quattro, to stop the SIGHUP re-entry that recurses until bash overflows its stack. The crash in #16807 is the same one #8386 and #8985 reported. The two differ only in where the regression test lives, so the older one stands and this one is closed as its duplicate.

There is a second reason neither can land on quattro as it is: fdbe182 ("Launch the native Wayland screensaver") deleted bin/omarchy-screensaver and the screensaver test this extends, and omarchy-launch-screensaver now execs the native omarchy-screensaver package. That is why GitHub shows a conflict here. The bash handler is still unfixed on the v4-5-0 and v4-0-6 release branches, so whether it gets backported there is with the maintainer, alongside #9042.

What was checked: both diffs side by side, the history of bin/omarchy-screensaver on quattro, and the handler on v4-5-0 and v4-0-6. Nothing was run, since the file no longer exists on the branch this targets. The classification as a bug was agreed by Codex Medium, and Codex Medium compared the two diffs separately before this was closed; independence between the two reviews is not guaranteed.

Thank you @AnPod for the careful reproduction. If this does something #9042 does not, reopen it with a note on the difference.

@omarchybot omarchybot added the duplicate This issue or pull request already exists label Nov 2, 2026
@omarchybot omarchybot closed this Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

omarchy-screensaver: SIGHUP trap re-enters exit_screensaver recursively until bash overflows its stack

2 participants