diff --git a/src/finit.c b/src/finit.c index 38b12788..49107a53 100644 --- a/src/finit.c +++ b/src/finit.c @@ -409,7 +409,7 @@ static void fs_finalize(void) * To override any of this behavior, add entries to /etc/fstab * for /run (and optionally /run/lock). */ - if (fisdir("/run") && !fismnt("/run")) { + if (fisdir("/run") && !fismnt("/run") && !fistmpfs("/run")) { fs_mount("tmpfs", "/run", "tmpfs", MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_RELATIME, "mode=0755,size=10%"); /* This prevents user DoS of /run by filling /run/lock at the expense of another tmpfs, max 5MiB */ @@ -418,7 +418,7 @@ static void fs_finalize(void) } /* Modern systems use tmpfs for /tmp */ - if (!fismnt("/tmp")) + if (!fismnt("/tmp") && !fistmpfs("/tmp")) fs_mount("tmpfs", "/tmp", "tmpfs", MS_NOSUID | MS_NODEV, "mode=1777"); } diff --git a/src/util.c b/src/util.c index 3029bc3d..4e8b0e4c 100644 --- a/src/util.c +++ b/src/util.c @@ -42,6 +42,8 @@ # include #endif #include /* sysinfo() */ +#include /* statfs */ +#include #ifdef _LIBITE_LITE # include #else @@ -572,6 +574,20 @@ int fismnt(char *dir) return ismnt("/proc/mounts", dir, NULL); } +/* Return 1 if dir is a backed by tmpfs or overlayfs */ +int fistmpfs(char *dir) +{ + struct statfs info = {0}; + + if (statfs(dir, &info)) + return 0; + + if (info.f_type == TMPFS_MAGIC || info.f_type == OVERLAYFS_SUPER_MAGIC) + return 1; + + return 0; +} + #ifdef HAVE_TERMIOS_H /* * Called by initctl, and by finit at boot and shutdown, to diff --git a/src/util.h b/src/util.h index 80e1c514..baff4081 100644 --- a/src/util.h +++ b/src/util.h @@ -80,6 +80,7 @@ void de_dotdot (char *file); int ismnt (char *file, char *dir, char *mode); int fismnt (char *dir); +int fistmpfs (char *dir); #ifdef HAVE_TERMIOS_H int ttinit (void);