This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository evisum.

View the commit online.

commit 29507eb1e39da76b1df44e36ce20b54efb67e0ac
Author: Alastair Poole <[email protected]>
AuthorDate: Tue Apr 28 00:59:16 2026 +0100

    engine: don't fucking fork all the time that's nuts
---
 src/bin/engine/evisum_engine.c | 99 +++++++++++++++++++++++++++++++++++++-----
 1 file changed, 88 insertions(+), 11 deletions(-)

diff --git a/src/bin/engine/evisum_engine.c b/src/bin/engine/evisum_engine.c
index 78d8c79..33b7326 100644
--- a/src/bin/engine/evisum_engine.c
+++ b/src/bin/engine/evisum_engine.c
@@ -11,6 +11,8 @@
 #include <limits.h>
 #include <time.h>
 #include <dirent.h>
+#include <errno.h>
+#include <signal.h>
 #include <sys/stat.h>
 
 #define LOCK() eina_lock_take(&_state.lock)
@@ -24,6 +26,7 @@ typedef struct {
     Eina_Condition cond;
     Eina_Bool cond_init;
     Eina_Bool started;
+    pid_t daemon_pid;
     uint64_t snapshot_seq;
 
     Enigmatic_Client *client;
@@ -54,6 +57,65 @@ _engine_snapshot_release(void);
 static void
 _engine_history_logs_free(Eina_List *logs);
 
+static Eina_Bool
+_engine_pid_alive(pid_t pid)
+{
+    if (pid <= 1) return EINA_FALSE;
+    if (kill(pid, 0) == 0) return EINA_TRUE;
+    return errno == EPERM;
+}
+
+static Eina_Bool
+_engine_pid_is_daemon(pid_t pid)
+{
+#if defined(__linux__)
+    char path[PATH_MAX];
+    char name[32];
+    FILE *f;
+
+    if (!_engine_pid_alive(pid)) return EINA_FALSE;
+
+    snprintf(path, sizeof(path), "/proc/%d/comm", pid);
+    f = fopen(path, "r");
+    if (!f) return EINA_FALSE;
+
+    if (!fgets(name, sizeof(name), f)) {
+        fclose(f);
+        return EINA_FALSE;
+    }
+    fclose(f);
+
+    char *nl = strchr(name, '\n');
+    if (nl) *nl = '\0';
+
+    return !strcmp(name, "enigmatic");
+#else
+    return _engine_pid_alive(pid);
+#endif
+}
+
+static pid_t
+_engine_daemon_pid_read(void)
+{
+    char *path;
+    pid_t pid;
+
+    path = enigmatic_pidfile_path();
+    if (!path) return 0;
+
+    pid = (pid_t) enigmatic_pidfile_pid_get(path);
+    free(path);
+
+    return _engine_pid_is_daemon(pid) ? pid : 0;
+}
+
+static pid_t
+_engine_daemon_pid_refresh_locked(void)
+{
+    _state.daemon_pid = _engine_daemon_pid_read();
+    return _state.daemon_pid;
+}
+
 static void
 _cb_snapshot_init(Enigmatic_Client *client EINA_UNUSED, Snapshot *s EINA_UNUSED, void *data EINA_UNUSED)
 {
@@ -91,6 +153,7 @@ _engine_start_locked(void)
     }
 
     enigmatic_client_monitor_add(_state.client, _cb_snapshot_init, _cb_snapshot, NULL);
+    _engine_daemon_pid_refresh_locked();
     _state.started = EINA_TRUE;
     return EINA_TRUE;
 }
@@ -138,6 +201,7 @@ evisum_engine_shutdown(void)
     _state.history_recent_logs_scan_at = 0;
 
     _state.started = EINA_FALSE;
+    _state.daemon_pid = 0;
     _state.history_enabled = EINA_FALSE;
     _state.history_time = 0;
     if (_state.cond_init) eina_condition_broadcast(&_state.cond);
@@ -179,7 +243,7 @@ evisum_engine_update_wait(uint64_t *seq)
 
     target = *seq ? *seq : _state.snapshot_seq;
     while (_state.started && _state.client) {
-        if (enigmatic_running() && (_state.snapshot_seq != target)) {
+        if (_state.snapshot_seq != target) {
             *seq = _state.snapshot_seq;
             UNLOCK();
             return EINA_TRUE;
@@ -194,24 +258,37 @@ evisum_engine_update_wait(uint64_t *seq)
 Eina_Bool
 evisum_engine_daemon_running_get(void)
 {
-    return enigmatic_running();
+    Eina_Bool running;
+
+    if (!_state.lock_init) return EINA_FALSE;
+
+    LOCK();
+    if (_state.daemon_pid && !_engine_pid_is_daemon(_state.daemon_pid))
+        _state.daemon_pid = 0;
+    if (!_state.daemon_pid && _state.started && _state.client)
+        _engine_daemon_pid_refresh_locked();
+    running = !!_state.daemon_pid;
+    UNLOCK();
+
+    return running;
 }
 
 pid_t
 evisum_engine_daemon_pid_get(void)
 {
-    char *path;
-    pid_t pid = 0;
+    pid_t pid;
 
-    if (!enigmatic_running()) return 0;
+    if (!_state.lock_init) return 0;
 
-    path = enigmatic_pidfile_path();
-    if (!path) return 0;
+    LOCK();
+    if (_state.daemon_pid && !_engine_pid_is_daemon(_state.daemon_pid))
+        _state.daemon_pid = 0;
+    if (!_state.daemon_pid && _state.started && _state.client)
+        _engine_daemon_pid_refresh_locked();
+    pid = _state.daemon_pid;
+    UNLOCK();
 
-    pid = (pid_t) enigmatic_pidfile_pid_get(path);
-    free(path);
-
-    return pid > 1 ? pid : 0;
+    return pid;
 }
 
 static Enigmatic_Client *

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to