From 16ace71839b74ca5d253faddaafb7e3886641acc Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Tue, 22 Dec 2020 09:54:38 +0300 Subject: =?UTF-8?q?src:=20Catch=20=E2=80=9Ckill=20exceptions=E2=80=9D?= =?UTF-8?q?=E2=80=99cleanly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the `kill` command is called in the `-E` CLI flag, the resulting exception is not caught and crashes the server. This commit allows the server to terminate cleanly. Since `KakEnd` hooks also need to be executed should the user run a command like `kak -E 'kill 0'`, the execution of `KakBegin` hooks is now performed *before* the command provided in `-E` is executed. The documentation for `KakBegin` (executed after the `-E` command prior to this commit) consequently becomes more truthful, as it states: KakBegin session name kakoune has started, this hook is called just after reading the user configuration files Fixes #3972 --- src/main.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main.cc b/src/main.cc index fbb074a0..6e8189da 100644 --- a/src/main.cc +++ b/src/main.cc @@ -792,11 +792,22 @@ int run_server(StringView session, StringView server_init, " {}", error.what())); } + { + Context empty_context{Context::EmptyContextFlag{}}; + global_scope.hooks().run_hook(Hook::KakBegin, session, empty_context); + } + if (not server_init.empty()) try { Context init_context{Context::EmptyContextFlag{}}; command_manager.execute(server_init, init_context); } + catch (const kill_session& kill) + { + Context empty_context{Context::EmptyContextFlag{}}; + global_scope.hooks().run_hook(Hook::KakEnd, "", empty_context); + return kill.exit_status; + } catch (runtime_error& error) { startup_error = true; @@ -804,11 +815,6 @@ int run_server(StringView session, StringView server_init, " {}", error.what())); } - { - Context empty_context{Context::EmptyContextFlag{}}; - global_scope.hooks().run_hook(Hook::KakBegin, session, empty_context); - } - if (not files.empty()) try { // create buffers in reverse order so that the first given buffer -- cgit v1.2.3