mirror of
https://github.com/troglobit/finit.git
synced 2026-10-01 05:22:48 +07:00
Allow matching of svc_t and pid file, prefer PID over file lookup
When a SysV init script starts a daemon, Finit knows nothing of the PID it should monitor. The PID is written, by start-stop-daemon or the daemon itself, to the PID file. Finit monitors for new PID files and can match the PID in such files with an svc_t. For the regular use-case, we prefer first looking up the matching svc_t based on the PID -- assuming we start and monitor the service. As a fallback we resort to mathching the svc_t's declared PID file with the new file we just discovered. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
@@ -473,23 +473,23 @@ svc_t *svc_find_by_pidfile(char *fn)
|
||||
pid_t pid;
|
||||
|
||||
pid = pid_file_read(fn);
|
||||
if (pid <= 0) {
|
||||
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;
|
||||
|
||||
if (pid > 1) {
|
||||
svc = svc_find_by_pid(pid);
|
||||
if (svc)
|
||||
return svc;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* No PID in file, or a sysv service. So it has probably forked
|
||||
* off a chiled that we don't know about. See if we can match
|
||||
* the PID file to a service instead.
|
||||
*/
|
||||
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
|
||||
if (svc->pid != pid)
|
||||
int v = 0;
|
||||
|
||||
if (svc->pidfile[0] == '!')
|
||||
v = 1;
|
||||
if (strcmp(&svc->pidfile[v], fn))
|
||||
continue;
|
||||
|
||||
return svc;
|
||||
|
||||
Reference in New Issue
Block a user