From 846692ca03719286976fd9261b6f3f9f3afa24b8 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sun, 20 Nov 2016 19:26:17 +0100 Subject: [PATCH] Fix #49: Skip tmpfs directories at bootclean We can safely skip tmpfs, nothing to clean from previous boot there. In fact, if we clean it we may spoil things for udev, which saves pre-boot files in /run/udev. Signed-off-by: Joachim Nilsson --- plugins/bootmisc.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/plugins/bootmisc.c b/plugins/bootmisc.c index 280dbf4e..5e7a2d50 100644 --- a/plugins/bootmisc.c +++ b/plugins/bootmisc.c @@ -22,6 +22,7 @@ */ #include +#include #include #include @@ -31,6 +32,28 @@ #include "../plugin.h" #include "../utmp-api.h" +static int is_tmpfs(char *dir) +{ + int tmpfs = 0; + FILE *fp; + struct mntent *mnt; + + fp = setmntent("/proc/mounts", "r"); + if (!fp) + return 0; /* Dunno, maybe not */ + + while ((mnt = getmntent(fp))) { + if (!strcmp(dir, mnt->mnt_dir)) + break; + } + + if (mnt && !strcmp("tmpfs", mnt->mnt_type)) + tmpfs = 1; + endmntent(fp); + + return tmpfs; +} + static void create(char *path, mode_t mode, uid_t uid, gid_t gid) { if (touch(path) || chmod(path, mode) || chown(path, uid, gid)) @@ -48,6 +71,7 @@ static int do_clean(const char *fpath, const struct stat *UNUSED(sb), int UNUSED return 0; } +/* We can safely skip tmpfs, nothing to clean from previous boot there */ static void bootclean(void) { char *dir[] = { @@ -57,8 +81,12 @@ static void bootclean(void) NULL }; - for (int i = 0; dir[i]; i++) + for (int i = 0; dir[i]; i++) { + if (is_tmpfs(dir[i])) + continue; + nftw(dir[i], do_clean, 20, FTW_DEPTH); + } } /*