From 32d9afc7bb0d34fbc9b8f6f456a75608d579203b Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sat, 13 Jan 2018 21:47:11 +0100 Subject: [PATCH] Use pid_runpath() in svc_find_by_pidfile(), used by pidfile plugin The pidfile plugin just listens to changes in files in /run or /var/run, so when trying to locate an svc_t from a file change we need to compare using the proper prefix path. Signed-off-by: Joachim Nilsson --- plugins/pidfile.c | 3 --- src/pid.c | 6 ++++-- src/svc.c | 4 +++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/pidfile.c b/plugins/pidfile.c index 8b48275d..e1641802 100644 --- a/plugins/pidfile.c +++ b/plugins/pidfile.c @@ -69,9 +69,6 @@ static void pidfile_callback(void *arg, int fd, int events) if (!svc) continue; - /* TODO FIXME XXX WKZ check that pid is controlled by finit */ - - _d("%s: match %s", ev->name, svc->cmd); mkcond(cond, sizeof(cond), svc->cmd); if (ev->mask & (IN_CREATE | IN_ATTRIB | IN_MODIFY)) { svc_started(svc); diff --git a/src/pid.c b/src/pid.c index 11ac3cba..8e2937ce 100644 --- a/src/pid.c +++ b/src/pid.c @@ -115,7 +115,8 @@ char *pid_runpath(char *file, char *path, size_t len) char *pid_file(svc_t *svc) { - static char fn[MAX_ARG_LEN]; + char fn[MAX_ARG_LEN]; + static char path[MAX_ARG_LEN]; if (svc->pidfile[0]) { if (svc->pidfile[0] == '!') @@ -124,7 +125,8 @@ char *pid_file(svc_t *svc) } snprintf(fn, sizeof(fn), "%s%s.pid", _PATH_VARRUN, basename(svc->cmd)); - return fn; + + return pid_runpath(fn, path, sizeof(path)); } int pid_file_create(svc_t *svc) diff --git a/src/svc.c b/src/svc.c index e51704b7..b1ceb78a 100644 --- a/src/svc.c +++ b/src/svc.c @@ -355,7 +355,9 @@ svc_t *svc_find_by_pidfile(char *fn) svc_t *svc, *iter = NULL; for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) { - if (string_compare(fn, pid_file(svc))) + char path[MAX_ARG_LEN]; + + if (string_compare(pid_runpath(fn, path, sizeof(path)), pid_file(svc))) return svc; }