Fix issue #42: Use ftw() to recursively clean up dirs.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2016-09-30 23:01:26 +02:00
1 parent d423e6b774
commit 07d767e1af
1 file changed
+23 -1
+23 -1
View File
@@ -25,6 +25,7 @@
#include "config.h" /* Generated by configure script */
#include <ctype.h>
#include <ftw.h>
#include <glob.h>
#include <dirent.h>
#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);