mirror of
https://github.com/aristocratos/btop.git
synced 2026-04-20 18:27:06 +02:00
Add crash handlers to restore terminal state
Install signal handlers for SIGSEGV, SIGABRT, SIGTRAP, SIGBUS, and SIGILL to restore terminal state before crashing. This prevents leaving the terminal in a broken state if btop crashes unexpectedly.
This commit is contained in:
16
src/btop.cpp
16
src/btop.cpp
@@ -256,6 +256,16 @@ static void _exit_handler() {
|
||||
clean_quit(-1);
|
||||
}
|
||||
|
||||
static void _crash_handler(const int sig) {
|
||||
// Restore terminal before crashing
|
||||
if (Term::initialized) {
|
||||
Term::restore();
|
||||
}
|
||||
// Re-raise the signal to get default behavior (core dump)
|
||||
std::signal(sig, SIG_DFL);
|
||||
std::raise(sig);
|
||||
}
|
||||
|
||||
static void _signal_handler(const int sig) {
|
||||
switch (sig) {
|
||||
case SIGINT:
|
||||
@@ -1014,6 +1024,12 @@ int main(const int argc, const char** argv) {
|
||||
std::signal(SIGWINCH, _signal_handler);
|
||||
std::signal(SIGUSR1, _signal_handler);
|
||||
std::signal(SIGUSR2, _signal_handler);
|
||||
// Add crash handlers to restore terminal on crash
|
||||
std::signal(SIGSEGV, _crash_handler);
|
||||
std::signal(SIGABRT, _crash_handler);
|
||||
std::signal(SIGTRAP, _crash_handler);
|
||||
std::signal(SIGBUS, _crash_handler);
|
||||
std::signal(SIGILL, _crash_handler);
|
||||
|
||||
sigset_t mask;
|
||||
sigemptyset(&mask);
|
||||
|
||||
Reference in New Issue
Block a user