From 488e6c2adffe565e16831a0be269287c0b5c4c41 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 16 Oct 2022 19:11:18 +0200 Subject: [PATCH] Follow-up to d82d1197: ensure PID file doesn't exist Before we clear all conditions for a service, ensure pid_file_read() didn't fail due to the PID file not (yet) containing a valid number. If the process dies while starting up, and subsequently removes its PID file, then the file shouldn't exist. However, if we get inotify before the process has finished writing the PID, then we just return and wait for the next event. Signed-off-by: Joachim Wiberg --- plugins/pidfile.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/pidfile.c b/plugins/pidfile.c index 4e3ab577..e75615ac 100644 --- a/plugins/pidfile.c +++ b/plugins/pidfile.c @@ -92,9 +92,11 @@ static void pidfile_update_conds(char *dir, char *name, uint32_t mask) if (svc_is_forking(svc)) { pid_t pid; - pid = pid_file_read(pid_file(svc)); + pid = pid_file_read(fn); if (pid == -1) { - cond_clear(cond); + /* handle case when service dies immediately */ + if (!fexist(fn)) + cond_clear(cond); return; }