From 47060c9738fc0adf5cac2b8e576fa94b91d8c433 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Mon, 21 Nov 2016 09:41:30 +0100 Subject: [PATCH] bootclean: Resolve any symlinks in tmpfs check Followup to issue #49. Signed-off-by: Joachim Nilsson --- plugins/bootmisc.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/plugins/bootmisc.c b/plugins/bootmisc.c index 5e7a2d50..e268f78e 100644 --- a/plugins/bootmisc.c +++ b/plugins/bootmisc.c @@ -32,12 +32,36 @@ #include "../plugin.h" #include "../utmp-api.h" +/* Resolve symbolic links */ +static char *desym(char *dir) +{ + static char path[80]; /* Should be enough for our use-case */ + struct stat st; + + if (stat(dir, &st)) + return NULL; + + if (S_ISLNK(st.st_mode)) { + if (-1 == readlink(dir, path, sizeof(path))) + return NULL; + + return desym(path); + } + + return dir; +} + static int is_tmpfs(char *dir) { int tmpfs = 0; FILE *fp; struct mntent *mnt; + /* If /var/run is a symlink, check what it resolves to */ + dir = desym(dir); + if (!dir) + return 0; /* Outlook not so good */ + fp = setmntent("/proc/mounts", "r"); if (!fp) return 0; /* Dunno, maybe not */