mirror of
https://github.com/troglobit/finit.git
synced 2026-11-01 13:10:32 +00:00
Drop svc pidfile matching, only match against PID in pidfile
With the redesign from <svc/path/to/pidfile> to <pid/name:id> in d1fac6f
we moved to matching svc_t only against their PID, which could pop up in
any *.pid or */pid in /var/run. This patch drops the (hopefully) last
remnants of the old <svc/> legacy.
To ensure we don't try reading the PID value from socket files, like
/var/run/initctl, we add simple fnmatch() of the inotified file. Two
calls to fnmatch(), for portability reasons, not every system has GNU
libc extensions like FNM_EXTMATCH.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
8dc1ad00d5
commit
dd6ebc3b65
2 files changed
+8
-23
No files matched your search
@@ -22,6 +22,7 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <fnmatch.h>
|
||||||
#include <glob.h>
|
#include <glob.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
@@ -69,6 +70,9 @@ static void pidfile_update_conds(char *dir, char *name, uint32_t mask)
|
|||||||
_d("Got dir: %s, name: %s, mask: %08x", dir, name, mask);
|
_d("Got dir: %s, name: %s, mask: %08x", dir, name, mask);
|
||||||
snprintf(fn, sizeof(fn), "%s/%s", dir, name);
|
snprintf(fn, sizeof(fn), "%s/%s", dir, name);
|
||||||
|
|
||||||
|
if (fnmatch("*\\.pid", fn, 0) && fnmatch("*/pid", fn, 0))
|
||||||
|
return;
|
||||||
|
|
||||||
svc = svc_find_by_pidfile(fn);
|
svc = svc_find_by_pidfile(fn);
|
||||||
if (!svc) {
|
if (!svc) {
|
||||||
_d("No matching svc for %s", fn);
|
_d("No matching svc for %s", fn);
|
||||||
|
|||||||
@@ -395,7 +395,7 @@ 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 a service 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
|
* This function is primarily used by the pidfile plugin to track the
|
||||||
@@ -412,32 +412,13 @@ svc_t *svc_find_by_nameid(char *name, char *id)
|
|||||||
svc_t *svc_find_by_pidfile(char *fn)
|
svc_t *svc_find_by_pidfile(char *fn)
|
||||||
{
|
{
|
||||||
svc_t *svc, *iter = NULL;
|
svc_t *svc, *iter = NULL;
|
||||||
char adjpath[strlen(fn) + 10]; /* + sizeof("/var/run/") */
|
pid_t pid;
|
||||||
char fnpath[PATH_MAX];
|
|
||||||
|
|
||||||
pid_runpath(fn, adjpath, sizeof(adjpath));
|
pid = pid_file_read(fn);
|
||||||
if (!realpath(adjpath, fnpath)) {
|
if (pid == -1)
|
||||||
if (errno != ENOENT)
|
|
||||||
_pe("adjpath: %s, errno %d", adjpath, errno);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
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[PATH_MAX];
|
|
||||||
char *pidfn;
|
|
||||||
pid_t pid;
|
|
||||||
|
|
||||||
pidfn = pid_file(svc);
|
|
||||||
if (!pidfn || !realpath(pidfn, path)) {
|
|
||||||
if (errno != ENOENT)
|
|
||||||
_pe("pidfn: %s, errno %d", pidfn ?: "<NULL>", errno);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string_compare(fnpath, path))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
pid = pid_file_read(path);
|
|
||||||
if (svc->pid != pid)
|
if (svc->pid != pid)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user