Handle SIGHUP gracefully

This commit is contained in:
Maxime Coste 2013-04-15 18:50:45 +02:00
parent cc91a71a96
commit da4be95c90
2 changed files with 7 additions and 2 deletions

View File

@ -49,9 +49,9 @@ public:
Client& get_client(const Context& context); Client& get_client(const Context& context);
Client& get_client(const String& name); Client& get_client(const String& name);
void set_client_name(Client& client, String name); void set_client_name(Client& client, String name);
void remove_client(Client& client);
private: private:
void remove_client(Client& client);
String generate_name() const; String generate_name() const;
std::vector<std::unique_ptr<Client>> m_clients; std::vector<std::unique_ptr<Client>> m_clients;

View File

@ -134,8 +134,13 @@ void create_local_client(const String& init_command)
}; };
UserInterface* ui = new LocalNCursesUI{}; UserInterface* ui = new LocalNCursesUI{};
ClientManager::instance().create_client( static Client* client = ClientManager::instance().create_client(
std::unique_ptr<UserInterface>{ui}, init_command); std::unique_ptr<UserInterface>{ui}, init_command);
signal(SIGHUP, [](int) {
if (client)
ClientManager::instance().remove_client(*client);
client = nullptr;
});
} }
void signal_handler(int signal) void signal_handler(int signal)