Skip to content

TUI: block signals on suspend (avoid kernel panic #8075) #12180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions src/nvim/os/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,13 @@ void signal_init(void)
signal_watcher_init(&main_loop, &shup, NULL);
signal_watcher_init(&main_loop, &squit, NULL);
signal_watcher_init(&main_loop, &sterm, NULL);
#ifdef SIGPIPE
signal_watcher_start(&spipe, on_signal, SIGPIPE);
#endif
signal_watcher_start(&shup, on_signal, SIGHUP);
#ifdef SIGQUIT
signal_watcher_start(&squit, on_signal, SIGQUIT);
#endif
signal_watcher_start(&sterm, on_signal, SIGTERM);
#ifdef SIGPWR
signal_watcher_init(&main_loop, &spwr, NULL);
signal_watcher_start(&spwr, on_signal, SIGPWR);
#endif
#ifdef SIGUSR1
signal_watcher_init(&main_loop, &susr1, NULL);
signal_watcher_start(&susr1, on_signal, SIGUSR1);
#endif
signal_start();
}

void signal_teardown(void)
Expand All @@ -83,11 +74,33 @@ void signal_teardown(void)
#endif
}

void signal_start(void)
{
#ifdef SIGPIPE
signal_watcher_start(&spipe, on_signal, SIGPIPE);
#endif
signal_watcher_start(&shup, on_signal, SIGHUP);
#ifdef SIGQUIT
signal_watcher_start(&squit, on_signal, SIGQUIT);
#endif
signal_watcher_start(&sterm, on_signal, SIGTERM);
#ifdef SIGPWR
signal_watcher_start(&spwr, on_signal, SIGPWR);
#endif
#ifdef SIGUSR1
signal_watcher_start(&susr1, on_signal, SIGUSR1);
#endif
}

void signal_stop(void)
{
#ifdef SIGPIPE
signal_watcher_stop(&spipe);
#endif
signal_watcher_stop(&shup);
#ifdef SIGQUIT
signal_watcher_stop(&squit);
#endif
signal_watcher_stop(&sterm);
#ifdef SIGPWR
signal_watcher_stop(&spwr);
Expand Down
3 changes: 3 additions & 0 deletions src/nvim/tui/tui.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "nvim/event/signal.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
#include "nvim/os/signal.h"
#include "nvim/os/tty.h"
#include "nvim/strings.h"
#include "nvim/syntax.h"
Expand Down Expand Up @@ -1239,7 +1240,9 @@ static void suspend_event(void **argv)
tui_terminal_stop(ui);
data->cont_received = false;
stream_set_blocking(input_global_fd(), true); // normalize stream (#2598)
signal_stop();
kill(0, SIGTSTP);
signal_start();
while (!data->cont_received) {
// poll the event loop until SIGCONT is received
loop_poll_events(data->loop, -1);
Expand Down