From 07d767e1af6282c780c0321f309d808d26b8ac91 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Fri, 30 Sep 2016 23:01:26 +0200 Subject: [PATCH] Fix issue #42: Use ftw() to recursively clean up dirs. Signed-off-by: Joachim Nilsson --- finit.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/finit.c b/finit.c index e1388a95..9a0c74bc 100644 --- a/finit.c +++ b/finit.c @@ -25,6 +25,7 @@ #include "config.h" /* Generated by configure script */ #include +#include #include #include #ifdef HAVE_FSTAB_H @@ -117,6 +118,27 @@ static int fsck(int pass) return 0; } +static int do_clean(const char *fpath, const struct stat *UNUSED(sb), int UNUSED(tflag), struct FTW *UNUSED(ftwbuf)) +{ + _d("Removing %s", fpath); + 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; @@ -378,7 +400,7 @@ int main(int argc, char* argv[]) umask(0022); /* Cleanup of stale files, if any still linger on. */ - run_interactive("rm -rf /tmp/* /tmp/.??* /var/run/* /var/lock/*", "Cleaning up temporary directories"); + bootclean(); /* Base FS up, enable standard SysV init signals */ sig_setup(&loop);