Handle SIGHUP gracefully
This commit is contained in:
parent
cc91a71a96
commit
da4be95c90
|
@ -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;
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user