Skip to content

sig_handler: use _exit() for SIGSEGV, keep exit() for clean shutdown - #142

Closed
Pace17881 wants to merge 1 commit into
FreeSpacenav:masterfrom
Pace17881:fix/sigsegv-handler-safe-exit
Closed

Pace17881 wants to merge 1 commit into
FreeSpacenav:masterfrom
Pace17881:fix/sigsegv-handler-safe-exit

Conversation

@Pace17881

Copy link
Copy Markdown

`exit()` is not async-signal-safe (POSIX) and runs the `atexit(cleanup)` handler, which tears down the X11 connection, unix socket, and devices. After a real segfault, process state may be corrupted, and running that same teardown code from within the signal handler could itself crash or hang - somewhat counterproductive for a handler whose whole point is to "exit gracefully".

This only changes the `SIGSEGV` case to call `_exit()` directly. `SIGINT`/`SIGTERM` keep using `exit()` as before, so normal shutdown still runs `cleanup()` and releases everything properly - only the segfault path skips it.

As a side effect, this also resolves the `-Wimplicit-fallthrough` warning under `-Wextra`, since `SIGSEGV` no longer falls through into the other cases (found while looking at the codebase with stricter warnings enabled, unrelated to the fix itself).

Small, self-contained change - happy to adjust if you'd prefer a different approach.

exit() is not async-signal-safe (POSIX) and runs the atexit(cleanup)
handler, which tears down the X11 connection, unix socket, and devices.
After a real segfault, process state may be corrupted, and running that
same teardown code could itself crash or hang - counterproductive for a
handler whose whole point is to "exit gracefully".

SIGINT/SIGTERM keep using exit() as before, so normal shutdown still runs
cleanup() and releases everything properly. Only SIGSEGV now calls
_exit() directly. This also resolves the -Wimplicit-fallthrough warning
under -Wextra, since SIGSEGV no longer falls through into the other cases.
@jtsiomb

jtsiomb commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Correct me if I'm wrong, but doesn't that make attempting to handle SIGSEGV completely pointless?

It was an attempt to maybe get the chance to clean some things up before exiting, if the situation allows it. But with your change we'll just exit immediately without any cleanup, which is what the default SIGSEGV handler would do anyway.

@Pace17881

Copy link
Copy Markdown
Author

Sorry for the noise — you're right, I hadn't considered that trading a chance at cleanup for a guaranteed no-op isn't actually an improvement. Closing this.

@Pace17881 Pace17881 closed this Sep 18, 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.

2 participants