From f9783b4b4140dec7bc22b8d33bd1debcdfa83c26 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sat, 13 Jan 2018 21:49:18 +0100 Subject: [PATCH] pidfile: Use realpath() to figure out of _PATH_VARRUN is a symlink Signed-off-by: Joachim Nilsson --- plugins/pidfile.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/pidfile.c b/plugins/pidfile.c index e1641802..44515b00 100644 --- a/plugins/pidfile.c +++ b/plugins/pidfile.c @@ -112,10 +112,23 @@ static void pidfile_reconf(void *arg) static void pidfile_init(void *arg) { + char *path; struct context *ctx = arg; - ctx->wd = inotify_add_watch(ctx->fd, _PATH_VARRUN, - IN_CREATE | IN_ATTRIB | IN_DELETE | IN_MODIFY); + /* + * The bootmisc plugin is responsible for setting up /var/run. + * and/or /run, with proper symlinks etc. We depend on bootmisc + * so it's safe here to query realpath() and set up inotify. + */ + path = realpath(_PATH_VARRUN, NULL); + if (!path) { + _pe("Failed "); + return; + } + + ctx->wd = inotify_add_watch(ctx->fd, path, IN_CREATE | IN_ATTRIB | IN_DELETE | IN_MODIFY); + free(path); + if (ctx->wd < 0) { _pe("inotify_add_watch()"); close(ctx->fd);