mirror of
https://github.com/troglobit/finit.git
synced 2026-11-20 19:41:51 +00:00
src: svc: Handle case where multiple services have same PID file
Services may exist in multiple runlevels, i.e. one behavior at bootstrap and another at runtime. If the user does not set a specific PID file to be used as condition finit can match the wrong svc. This patch extends svc_find_by_pidfile() to also compare the contents of the PID file with the PID of the registered svc_t. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
aa08221666
commit
3865ce765e
1 file changed
+18
-2
@@ -376,6 +376,14 @@ svc_t *svc_find_by_nameid(char *name, char *id)
|
|||||||
* svc_find_by_plidfile - Find an service object by its PID file
|
* svc_find_by_plidfile - Find an service object by its PID file
|
||||||
* @fn: PID file, can be absolute path or relative to /run
|
* @fn: PID file, can be absolute path or relative to /run
|
||||||
*
|
*
|
||||||
|
* This function is primarily used by the pidfile plugin to track the
|
||||||
|
* conditions and dependencies of services.
|
||||||
|
*
|
||||||
|
* Note, the PID file is assumed to exist so the contents can be
|
||||||
|
* compared to the the PID of a located service. There may be several
|
||||||
|
* services, in many runlevels, that use the same name for the PID file.
|
||||||
|
* So we won't know for sure until the PID is compared.
|
||||||
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* A pointer to an &svc_t object, or %NULL if not found.
|
* A pointer to an &svc_t object, or %NULL if not found.
|
||||||
*/
|
*/
|
||||||
@@ -385,9 +393,17 @@ svc_t *svc_find_by_pidfile(char *fn)
|
|||||||
|
|
||||||
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
|
for (svc = svc_iterator(&iter, 1); svc; svc = svc_iterator(&iter, 0)) {
|
||||||
char path[MAX_ARG_LEN];
|
char path[MAX_ARG_LEN];
|
||||||
|
pid_t pid;
|
||||||
|
|
||||||
if (string_compare(pid_runpath(fn, path, sizeof(path)), pid_file(svc)))
|
pid_runpath(fn, path, sizeof(path));
|
||||||
return svc;
|
if (!string_compare(path, pid_file(svc)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
pid = pid_file_read(path);
|
||||||
|
if (svc->pid != pid)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
return svc;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in new issue
Block a user