diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2026-01-04 13:12:57 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2026-01-04 13:19:26 +0100 |
| commit | 9f133c83126c77b05b18e3b3def8a9394d6b42f9 (patch) | |
| tree | 09c978f9922bf112c1cd5cfa7479486b01ad2e37 | |
| parent | 36b52cf87f6d69854a3e951bd1062fe6857e64de (diff) | |
| download | vis-9f133c83126c77b05b18e3b3def8a9394d6b42f9.tar.gz vis-9f133c83126c77b05b18e3b3def8a9394d6b42f9.tar.xz | |
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.
| -rw-r--r-- | main.c | 42 |
1 files changed, 23 insertions, 19 deletions
@@ -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; |
