From 208f9641ef8e7b5900bbbd88b2852dfa434ebfee Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 12 Nov 2017 22:28:13 +0800 Subject: [PATCH] Remote: when converting to client, suspend *after* connecting Also, do not quit server while there is a connection being accepted Fixes #1690 --- src/main.cc | 14 +++++++++----- src/remote.hh | 2 ++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main.cc b/src/main.cc index 6feb37b8..4671511a 100644 --- a/src/main.cc +++ b/src/main.cc @@ -503,13 +503,16 @@ std::unique_ptr create_local_ui(UIType ui_type) } int run_client(StringView session, StringView client_init, - Optional init_coord, UIType ui_type) + Optional init_coord, UIType ui_type, + bool suspend) { try { EventManager event_manager; RemoteClient client{session, make_ui(ui_type), getpid(), get_env_vars(), client_init, std::move(init_coord)}; + if (suspend) + raise(SIGTSTP); while (not client.exit_status()) event_manager.handle_next_events(EventMode::Normal); return *client.exit_status(); @@ -661,7 +664,9 @@ int run_server(StringView session, StringView server_init, local_client->info_show("Welcome to Kakoune", startup_info, {}, InfoStyle::Prompt); } - while (not terminate and (not client_manager.empty() or (flags & ServerFlags::Daemon))) + while (not terminate and + (not client_manager.empty() or server.negotiating() or + (flags & ServerFlags::Daemon))) { client_manager.redraw_clients(); event_manager.handle_next_events(EventMode::Normal); @@ -980,7 +985,7 @@ int main(int argc, char* argv[]) for (auto name : files) new_files += format("edit '{}';", escape(real_path(name), "'", '\\')); - return run_client(*server_session, new_files + client_init, init_coord, ui_type); + return run_client(*server_session, new_files + client_init, init_coord, ui_type, false); } else { @@ -995,10 +1000,9 @@ int main(int argc, char* argv[]) } catch (convert_to_client_mode& convert) { - raise(SIGTSTP); return run_client(convert.session, format("try %^buffer '{}'; select '{}'^; echo converted to client only mode", - escape(convert.buffer_name, "'^", '\\'), convert.selections), {}, ui_type); + escape(convert.buffer_name, "'^", '\\'), convert.selections), {}, ui_type, true); } } } diff --git a/src/remote.hh b/src/remote.hh index b270bc47..d723713f 100644 --- a/src/remote.hh +++ b/src/remote.hh @@ -53,6 +53,8 @@ struct Server : public Singleton bool rename_session(StringView name); void close_session(bool do_unlink = true); + bool negotiating() const { return not m_accepters.empty(); } + private: class Accepter; void remove_accepter(Accepter* accepter);