From 9f133c83126c77b05b18e3b3def8a9394d6b42f9 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sun, 4 Jan 2026 13:12:57 +0100 Subject: main: initialize signal handling before other parts of the editor There is a period during vis' initialization where our signal handler is not yet registered and we potentially lose not handled signals. This time window is dependent on the lua code executed during the EVENT_INIT event and can be arbitrary long dependent of the user's config. Decrease the window for lost signals by registering our signal handler and blocking the signals for the rest of the editor's startup immediately after parsing the command options. --- main.c | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/main.c b/main.c index ff8b550..e336916 100644 --- a/main.c +++ b/main.c @@ -1293,25 +1293,10 @@ int main(int argc, char *argv[]) if (!vis_init(vis)) return EXIT_FAILURE; - vis_event_emit(vis, VIS_EVENT_INIT); - - for (int i = 0; i < LENGTH(vis_action); i++) { - if (!vis_action_register(vis, vis_action + i)) - vis_die(vis, "Could not register action: %s\n", vis_action[i].name); - } - - for (int i = 0; i < LENGTH(default_bindings); i++) { - for (const KeyBinding **binding = default_bindings[i]; binding && *binding; binding++) { - for (const KeyBinding *kb = *binding; kb->key; kb++) { - vis_mode_map(vis, i, false, kb->key, kb); - } - } - } - - for (const char **k = keymaps; k[0]; k += 2) - vis_keymap_add(vis, k[0], k[1]); - - /* install signal handlers etc. */ + /* install signal handlers etc. + * Do it before any external lua code is run by EVENT_INIT to prevent lost + * signals. + */ struct sigaction sa; memset(&sa, 0, sizeof sa); sigfillset(&sa.sa_mask); @@ -1340,6 +1325,25 @@ int main(int argc, char *argv[]) if (sigprocmask(SIG_BLOCK, &blockset, NULL) == -1) vis_die(vis, "Failed to block signals\n"); + vis_event_emit(vis, VIS_EVENT_INIT); + + for (int i = 0; i < LENGTH(vis_action); i++) { + if (!vis_action_register(vis, vis_action + i)) + vis_die(vis, "Could not register action: %s\n", vis_action[i].name); + } + + for (int i = 0; i < LENGTH(default_bindings); i++) { + for (const KeyBinding **binding = default_bindings[i]; binding && *binding; binding++) { + for (const KeyBinding *kb = *binding; kb->key; kb++) { + vis_mode_map(vis, i, false, kb->key, kb); + } + } + } + + for (const char **k = keymaps; k[0]; k += 2) + vis_keymap_add(vis, k[0], k[1]); + + char *cmd = NULL; bool end_of_options = false, win_created = false; -- cgit v1.2.3