Allow quiting last client with unsaved buffer in daemon mode

Because the server will out-live that client's disconnection it
is still ok to have modified buffers, the server will complain
on `kill`.

Fixes #3801
This commit is contained in:
Maxime Coste 2020-10-19 20:39:25 +11:00
parent 97e88b6087
commit 2cd323b314
4 changed files with 11 additions and 8 deletions

View File

@ -623,7 +623,7 @@ const CommandDesc force_kill_cmd = {
template<bool force>
void quit(const ParametersParser& parser, Context& context, const ShellContext&)
{
if (not force and ClientManager::instance().count() == 1)
if (not force and ClientManager::instance().count() == 1 and not Server::instance().is_daemon())
ensure_all_buffers_are_saved();
const int status = parser.positional_count() > 0 ? str_to_int(parser[0]) : 0;

View File

@ -740,7 +740,8 @@ int run_server(StringView session, StringView server_init,
}
EventManager event_manager;
Server server{session.empty() ? to_string(getpid()) : session.str()};
Server server{session.empty() ? to_string(getpid()) : session.str(),
(bool)(flags & ServerFlags::Daemon)};
StringRegistry string_registry;
GlobalScope global_scope;
@ -832,7 +833,7 @@ int run_server(StringView session, StringView server_init,
try
{
if (not (flags & ServerFlags::Daemon))
if (not server.is_daemon())
{
local_client = client_manager.create_client(
create_local_ui(ui_type), getpid(), {}, get_env_vars(), client_init, std::move(init_coord),
@ -849,8 +850,7 @@ int run_server(StringView session, StringView server_init,
}
while (not terminate and
(not client_manager.empty() or server.negotiating() or
(flags & ServerFlags::Daemon)))
(not client_manager.empty() or server.negotiating() or server.is_daemon()))
{
client_manager.redraw_clients();

View File

@ -849,8 +849,8 @@ private:
MsgReader m_reader;
};
Server::Server(String session_name)
: m_session{std::move(session_name)}
Server::Server(String session_name, bool is_daemon)
: m_session{std::move(session_name)}, m_is_daemon{is_daemon}
{
if (not all_of(m_session, is_identifier))
throw runtime_error{format("invalid session name: '{}'", session_name)};

View File

@ -50,7 +50,7 @@ String session_path(StringView session);
struct Server : public Singleton<Server>
{
Server(String session_name);
Server(String session_name, bool daemon);
~Server();
const String& session() const { return m_session; }
@ -59,11 +59,14 @@ struct Server : public Singleton<Server>
bool negotiating() const { return not m_accepters.empty(); }
bool is_daemon() const { return m_is_daemon; }
private:
class Accepter;
void remove_accepter(Accepter* accepter);
String m_session;
bool m_is_daemon;
std::unique_ptr<FDWatcher> m_listener;
Vector<std::unique_ptr<Accepter>, MemoryDomain::Remote> m_accepters;
};