Repository navigation
Restore the terminal when a fault or abort signal ends PrismTTY - #251
Merged
Merged
Conversation
SIGABRT, SIGTRAP, SIGILL, SIGFPE, SIGSYS, SIGBUS, SIGSEGV and, on macOS, SIGEMT ended PrismTTY with its terminal still in raw mode. A last-chance handler now restores the saved terminal mode, chains the runtime's stack-overflow handler for SIGBUS and SIGSEGV, puts the default action back and sends the signal again, so PrismTTY still dies from it. A SIGBUS or SIGSEGV sent from outside interrupted the stream read and became an I/O error with exit 1. The read is retried now, and in a wrapped session the signal ends PrismTTY as itself.
…e faulting thread
…ved predecessor published, withdraw only a new snapshot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
Two things, measured on 1.6.8 (macOS, Apple silicon):
reset.kill -SEGVorkill -BUSmade PrismTTY printI/O error: Interrupted system call (os error 4)and exit 1. Rust's own stack-overflow handler takes these two signals, resets them and returns, and that return interrupted the stream read.What changes
command | prismtty) starts no terminal session and is unchanged.Measured (19 rows, 1.6.8 against this branch)
Real faults (a null store, an undefined instruction) and a real Rust stack overflow are covered by tests that check the wait status and the complete terminal mode. On macOS, the crash reports of one measured run still showed the original fault: for the null store the exception type, the address, the thread and the faulting frame; for the undefined instruction the exception type, the thread and the faulting frame.
Limits (in the README)
Best effort: no restore when PrismTTY does not own the terminal foreground at the check, or when the terminal write fails; a signal that was ignored or already handled when the session began is left alone; this path does not draw buffered output or tear down the command; if the default action cannot be installed or nothing can be sent, PrismTTY exits with 128 plus the signal number instead.
For programs that use the library rather than the command: when sessions overlap in one process only the first has this last-chance restore, and a thread that is already inside an earlier SIGBUS or SIGSEGV handler when the session starts can still put the default action back.
Not measured
Core files. On Linux the new tests ran for the first time in this pull request's CI (Ubuntu, x86-64) and pass, including the real-fault, abort and stack-overflow tests; the 19-row table itself was measured on macOS only.
Tests
macOS, Apple silicon: fmt and clippy clean, 1339 Rust tests and the node tests pass, privacy scan clean. Each new test was run 10 or 20 times in a row, and the whole library suite three times, with no failure. The new start-order test fails on the old order and passes on the new.