summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFrank LENORMAND <lenormf@gmail.com>2020-12-22 09:54:38 +0300
committerFrank LENORMAND <lenormf@gmail.com>2020-12-22 09:54:38 +0300
commit16ace71839b74ca5d253faddaafb7e3886641acc (patch)
tree280a5f7c78fe9e1083a77d3b2cc6ead646eaa166 /src
parent74b6c20a0d19c9fcf2b30a93de1ff3b715151e65 (diff)
src: Catch “kill exceptions”’cleanly
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
Diffstat (limited to 'src')
-rw-r--r--src/main.cc16
1 files changed, 11 insertions, 5 deletions
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