mirror of
https://github.com/troglobit/finit.git
synced 2026-10-02 05:52:48 +07:00
plugins: pidfile: track PID file in svc, if svc has none declared
Services that create their own PID files usually don't declare one with Finit. This patch adds support to track those PID files anywayt at runtime for the purpose of identifying match svc_t when a PID file is removed, i.e. when a service exits. - On IN_CREATE the pidfile.so plugin saves the pid file name in svc_t - On ON_DELETE the pidfile.so plugin finds svc_t based on pid file Quicker tracking and less dead code, win-win. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
@@ -84,6 +84,9 @@ static void pidfile_update_conds(char *dir, char *name, uint32_t mask)
|
||||
mkcond(svc, cond, sizeof(cond));
|
||||
if (mask & (IN_CLOSE_WRITE | IN_ATTRIB | IN_MODIFY | IN_MOVED_TO)) {
|
||||
svc_started(svc);
|
||||
if (!svc_has_pidfile(svc))
|
||||
pid_file_set(svc, fn, 1);
|
||||
|
||||
if (svc_is_forking(svc)) {
|
||||
pid_t pid;
|
||||
|
||||
|
||||
@@ -416,7 +416,17 @@ svc_t *svc_find_by_pidfile(char *fn)
|
||||
|
||||
pid = pid_file_read(fn);
|
||||
if (pid <= 0) {
|
||||
_d("pid_file_read(%s) => %d", fn, pid);
|
||||
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
|
||||
int v = 0;
|
||||
|
||||
if (svc->pidfile[0] == '!')
|
||||
v = 1;
|
||||
if (strcmp(&svc->pidfile[v], fn))
|
||||
continue;
|
||||
|
||||
return svc;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user