Skip to content

Disarm the screensaver's signal traps before its cleanup runs - #9166

Closed
omarchybot wants to merge 1 commit into
quattrofrom
fix/issue-8386
Closed

omarchybot wants to merge 1 commit into
quattrofrom
fix/issue-8386

Conversation

@omarchybot

Copy link
Copy Markdown
Collaborator

exit_screensaver closes the terminal that owns this script's own pty, and bash re-enters a trap for the signal it is already handling — SIGWINCH and SIGCHLD have their own machinery, HUP, INT, TERM and QUIT do not — so every hangup arriving while the handler is still running nests it one level deeper. Under a terminal that keeps hanging the pty up, that runs until bash exhausts its stack and dies with SIGSEGV, which is what the cores on #8386 show: the oldest frame is zread from this script's read -n1 -t 1, then run_pending_traps → parse_and_execute → execute_command_internal around 21,500 times over.

The disarm has to be the trap's own first command. At the top of the function it is one command too late, because bash can re-enter at the call boundary before the function body starts. Driving the unmodified script from a real pty on an Omarchy 4.0.1-1 worker (bash 5.3.15-1) under a sustained hangup, eight runs each: the shipped handler segfaulted 8 of 8, disarming as the function's first statement 2 of 8, disarming as the trap's first command 0 of 8 — and 0 of 23 over every run of that shape. The function keeps a disarm of its own so the direct call from the read loop cleans up once rather than twice.

trap : rather than trap '', because an ignored disposition survives exec: trap '' would leave the hyprctl and pkill children spawned afterwards immune to SIGTERM as well.

What this does not do is explain why the reporter's terminal hangs the pty up thousands of times. Nothing in this repository produces that, and the fix does not depend on knowing: the handler is safe at any count.

This touches the same handler as #6813 and conflicts with it textually. That PR's guard — a shutdown flag and trap '' inside request_shutdown — has the same late-disarm window, and measured the same way it segfaulted 4 of 8 runs, so the disarm still needs to move ahead of the function call if #6813 lands instead.

Reviewed by Codex GPT-5.6 at xhigh reasoning, which found the pre-disarm re-entry window independently and is why the disarm moved into the trap string.

Fixes #8386

exit_screensaver closes the terminal that owns this script's own pty, and bash
re-enters a trap for the signal it is already handling, so every hangup that
teardown sends back nests the handler one level deeper until the stack is gone.

Disarming as the function's first statement is one command too late, because
bash can re-enter at the call boundary before the body starts. Driving the real
script from a pty on an Omarchy 4.0.1-1 worker under a sustained hangup, eight
runs each: the shipped handler segfaulted 8 times, disarming inside the function
2, and disarming as the trap's own first command 0.

trap : rather than trap '' because an ignored disposition survives exec, which
would leave the hyprctl and pkill children immune to SIGTERM too.

Co-Authored-By: Codex GPT-5.6 <codex@openai.com>
@bjarneo

bjarneo commented Sep 21, 2026

Copy link
Copy Markdown
Member

Automated duplication check: this pull request looks similar to #9042, which covers the same screensaver exit once. I keep that one open and close this one to consolidate review.

If you feel this is the wrong decision, please open the PR again with a note on the difference.

@bjarneo bjarneo closed this Sep 21, 2026
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.

omarchy-screensaver recursively handles SIGHUP until Bash segfaults

2 participants