mirror of
https://github.com/troglobit/finit.git
synced 2026-11-13 17:00:16 +00:00
src: svc: Use realpath() to check if untangled file exists
The svc_find_by_pidfile() function may be called with "/run/./foo.pid", or similar, which must be sanitized before being compared to the PID file of each svc_t. This patch introduce realpath() to untangle the paths and check if the file actually exists. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
3865ce765e
commit
6306c757a2
1 file changed
+18
-3
@@ -390,13 +390,28 @@ 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/") */
|
||||||
|
char fnpath[PATH_MAX];
|
||||||
|
|
||||||
|
pid_runpath(fn, adjpath, sizeof(adjpath));
|
||||||
|
if (!realpath(adjpath, fnpath)) {
|
||||||
|
_pe("adjpath: %s, errno %d", adjpath, errno);
|
||||||
|
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[MAX_ARG_LEN];
|
char path[PATH_MAX];
|
||||||
|
char *pidfn;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
pid_runpath(fn, path, sizeof(path));
|
pidfn = pid_file(svc);
|
||||||
if (!string_compare(path, 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;
|
continue;
|
||||||
|
|
||||||
pid = pid_file_read(path);
|
pid = pid_file_read(path);
|
||||||
|
|||||||
Reference in new issue
Block a user