aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2026-01-04 13:12:57 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2026-01-04 13:19:26 +0100
commit9f133c83126c77b05b18e3b3def8a9394d6b42f9 (patch)
tree09c978f9922bf112c1cd5cfa7479486b01ad2e37 /main.c
parent36b52cf87f6d69854a3e951bd1062fe6857e64de (diff)
downloadvis-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.
Diffstat (limited to 'main.c')
-rw-r--r--main.c42
1 files 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;