From da4be95c903f0a7a442d0cf445d6229a978e8764 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 15 Apr 2013 18:50:45 +0200 Subject: [PATCH] Handle SIGHUP gracefully --- src/client_manager.hh | 2 +- src/main.cc | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/client_manager.hh b/src/client_manager.hh index 3c964b2c..8501e3ea 100644 --- a/src/client_manager.hh +++ b/src/client_manager.hh @@ -49,9 +49,9 @@ public: Client& get_client(const Context& context); Client& get_client(const String& name); void set_client_name(Client& client, String name); + void remove_client(Client& client); private: - void remove_client(Client& client); String generate_name() const; std::vector> m_clients; diff --git a/src/main.cc b/src/main.cc index bd5b43b2..927aebb0 100644 --- a/src/main.cc +++ b/src/main.cc @@ -134,8 +134,13 @@ void create_local_client(const String& init_command) }; UserInterface* ui = new LocalNCursesUI{}; - ClientManager::instance().create_client( + static Client* client = ClientManager::instance().create_client( std::unique_ptr{ui}, init_command); + signal(SIGHUP, [](int) { + if (client) + ClientManager::instance().remove_client(*client); + client = nullptr; + }); } void signal_handler(int signal)