From a013e48ab547fa4e378b8bf317b550c694e8e70e Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sun, 9 Oct 2016 23:08:44 +0200 Subject: [PATCH] Run bootclean() from bootmisc plugin instead This patch moves both the definition and the call to bootclean() from finit.c to the bootmisc plugin. We want to call bootclean() *after* any /run and /var file systems have been mounted. Signed-off-by: Joachim Nilsson --- finit.c | 27 --------------------------- plugins/bootmisc.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/finit.c b/finit.c index 48f26451..daee28df 100644 --- a/finit.c +++ b/finit.c @@ -25,7 +25,6 @@ #include "config.h" /* Generated by configure script */ #include -#include #include #include #ifdef HAVE_FSTAB_H @@ -118,29 +117,6 @@ static int fsck(int pass) return 0; } -static int do_clean(const char *fpath, const struct stat *UNUSED(sb), int UNUSED(tflag), struct FTW *ftwbuf) -{ - if (ftwbuf->level == 0) - return 1; - - (void)remove(fpath); - - return 0; -} - -static void bootclean(void) -{ - char *dir[] = { - "/tmp/", - "/var/run/", - "/var/lock/", - NULL - }; - - for (int i = 0; dir[i]; i++) - nftw(dir[i], do_clean, 20, FTW_DEPTH); -} - static void networking(void) { size_t i; @@ -401,9 +377,6 @@ int main(int argc, char* argv[]) run("/sbin/swapon -ea"); umask(0022); - /* Cleanup of stale files, if any still linger on. */ - bootclean(); - /* Base FS up, enable standard SysV init signals */ sig_setup(&loop); diff --git a/plugins/bootmisc.c b/plugins/bootmisc.c index b14d83ae..33a03594 100644 --- a/plugins/bootmisc.c +++ b/plugins/bootmisc.c @@ -21,6 +21,7 @@ * THE SOFTWARE. */ +#include #include #include @@ -36,6 +37,30 @@ static void create(char *path, mode_t mode, uid_t uid, gid_t gid) _w("Failed creating %s properl.", path); } +static int do_clean(const char *fpath, const struct stat *UNUSED(sb), int UNUSED(tflag), struct FTW *ftwbuf) +{ + if (ftwbuf->level == 0) + return 1; + + _e("Removing %s ...", fpath); + (void)remove(fpath); + + return 0; +} + +static void bootclean(void) +{ + char *dir[] = { + "/tmp/", + "/var/run/", + "/var/lock/", + NULL + }; + + for (int i = 0; dir[i]; i++) + nftw(dir[i], do_clean, 20, FTW_DEPTH); +} + /* * Setup standard FHS 2.3 structure in /var, and write runlevel to UTMP */ @@ -43,9 +68,11 @@ static void setup(void *UNUSED(arg)) { int gid; - umask(0); + /* Cleanup stale files, if any still linger on. */ + bootclean(); _d("Setting up FHS structure in /var ..."); + umask(0); makedir("/var/cache", 0755); makedir("/var/games", 0755); makedir("/var/lib", 0755);