From af70305ccc99a4058e6d5543ea5872a1abdc00bf Mon Sep 17 00:00:00 2001
From: Federico Terzi <federicoterzi96@gmail.com>
Date: Wed, 13 Oct 2021 21:17:17 +0200
Subject: [PATCH] fix(core): fix edge case that prevented daemon from detecting
 a worker failure due to a signal. Fix #788

---
 espanso/src/cli/daemon/mod.rs | 8 ++++++--
 espanso/src/exit_code.rs      | 1 +
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/espanso/src/cli/daemon/mod.rs b/espanso/src/cli/daemon/mod.rs
index 4543f17..1b1c2fe 100644
--- a/espanso/src/cli/daemon/mod.rs
+++ b/espanso/src/cli/daemon/mod.rs
@@ -32,8 +32,8 @@ use crate::{
   common_flags::*,
   exit_code::{
     DAEMON_ALREADY_RUNNING, DAEMON_FATAL_CONFIG_ERROR, DAEMON_GENERAL_ERROR,
-    DAEMON_LEGACY_ALREADY_RUNNING, DAEMON_SUCCESS, WORKER_EXIT_ALL_PROCESSES, WORKER_RESTART,
-    WORKER_SUCCESS,
+    DAEMON_LEGACY_ALREADY_RUNNING, DAEMON_SUCCESS, WORKER_ERROR_EXIT_NO_CODE,
+    WORKER_EXIT_ALL_PROCESSES, WORKER_RESTART, WORKER_SUCCESS,
   },
   ipc::{create_ipc_client_to_worker, IPCEvent},
   lock::{acquire_daemon_lock, acquire_legacy_lock, acquire_worker_lock},
@@ -271,6 +271,10 @@ fn spawn_worker(
               .send(code)
               .expect("unable to forward worker exit code");
           }
+        } else {
+          exit_notify
+            .send(WORKER_ERROR_EXIT_NO_CODE)
+            .expect("unable to forward worker exit code");
         }
       }
     })
diff --git a/espanso/src/exit_code.rs b/espanso/src/exit_code.rs
index f99d1b0..01ade17 100644
--- a/espanso/src/exit_code.rs
+++ b/espanso/src/exit_code.rs
@@ -23,6 +23,7 @@ pub const WORKER_GENERAL_ERROR: i32 = 2;
 pub const WORKER_LEGACY_ALREADY_RUNNING: i32 = 3;
 pub const WORKER_EXIT_ALL_PROCESSES: i32 = 50;
 pub const WORKER_RESTART: i32 = 51;
+pub const WORKER_ERROR_EXIT_NO_CODE: i32 = 90;
 
 pub const DAEMON_SUCCESS: i32 = 0;
 pub const DAEMON_ALREADY_RUNNING: i32 = 1;