From c2989704d55c9fe9c7142fd298da38d5b7c780a9 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 14 Nov 2016 00:49:34 +0000 Subject: [PATCH] More correct handling of SIGHUP while suspended Fixes #833 --- src/main.cc | 4 ++-- src/ncurses_ui.cc | 12 +++++++++++- src/ncurses_ui.hh | 4 ++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main.cc b/src/main.cc index 1a993c98..dc25efc8 100644 --- a/src/main.cc +++ b/src/main.cc @@ -357,6 +357,7 @@ std::unique_ptr create_local_ui(UIType ui_type) local_ui = this; m_old_sighup = set_signal_handler(SIGHUP, [](int) { ClientManager::instance().remove_client(*local_client, false); + static_cast(local_ui)->on_sighup(); }); m_old_sigtstp = set_signal_handler(SIGTSTP, [](int) { @@ -373,9 +374,8 @@ std::unique_ptr create_local_ui(UIType ui_type) raise(SIGTSTP); - sigprocmask(SIG_SETMASK, &old_mask, nullptr); - set_signal_handler(SIGTSTP, current); + sigprocmask(SIG_SETMASK, &old_mask, nullptr); } else convert_to_client_pending = true; diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc index e3c235ee..5d3627df 100644 --- a/src/ncurses_ui.cc +++ b/src/ncurses_ui.cc @@ -480,8 +480,19 @@ void NCursesUI::check_resize(bool force) werase(curscr); } +void NCursesUI::on_sighup() +{ + set_signal_handler(SIGWINCH, SIG_DFL); + set_signal_handler(SIGCONT, SIG_DFL); + + m_window = nullptr; +} + bool NCursesUI::is_key_available() { + if (not m_window) + return false; + check_resize(); wtimeout(m_window, 0); @@ -492,7 +503,6 @@ bool NCursesUI::is_key_available() return c != ERR; } - Key NCursesUI::get_key() { check_resize(); diff --git a/src/ncurses_ui.hh b/src/ncurses_ui.hh index 1b094c1d..6efbbcea 100644 --- a/src/ncurses_ui.hh +++ b/src/ncurses_ui.hh @@ -59,6 +59,10 @@ public: DisplayCoord pos; DisplayCoord size; }; + +protected: + void on_sighup(); + private: void check_resize(bool force = false); void redraw();