From 33ae64495ab92f8a7a8a69ea2d74904b884b1ac4 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Tue, 24 Jan 2017 07:57:19 +0100 Subject: [PATCH] finit.c: Mount /proc and /sys before fsck() For issue #64 we need to have /proc/mounts, or /etc/mtab but that's usually symlinked to /proc/mounts. Signed-off-by: Joachim Nilsson --- src/finit.c | 60 ++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/finit.c b/src/finit.c index edb9cf52..6c650932 100644 --- a/src/finit.c +++ b/src/finit.c @@ -77,6 +77,28 @@ static int banner(void) return 0; } +/* Requires /proc to be mounted */ +static int fismnt(char *dir) +{ + FILE *fp; + int found = 0; + struct mntent *mnt; + + fp = setmntent("/proc/mounts", "r"); + if (!fp) + return 0; /* Dunno, maybe not */ + + while ((mnt = getmntent(fp))) { + if (!strcmp(mnt->mnt_dir, dir)) { + found = 1; + break; + } + } + endmntent(fp); + + return found; +} + /* * Check all filesystems in /etc/fstab with a fs_passno > 0 */ @@ -164,28 +186,6 @@ static void networking(void) ifconfig("lo", "127.0.0.1", "255.0.0.0", 1); } -/* Requires /proc to be mounted */ -static int fismnt(char *dir) -{ - FILE *fp; - int found = 0; - struct mntent *mnt; - - fp = setmntent("/proc/mounts", "r"); - if (!fp) - return 0; /* Dunno, maybe not */ - - while ((mnt = getmntent(fp))) { - if (!strcmp(mnt->mnt_dir, dir)) { - found = 1; - break; - } - } - endmntent(fp); - - return found; -} - /* * If everything goes south we can use this to give the operator an * emergency shell to debug the problem -- Finit should not crash! @@ -246,14 +246,6 @@ int main(int argc, char* argv[]) uev_init(&loop); ctx = &loop; - /* - * Check file filesystems in /etc/fstab - */ - for (int pass = 1; pass < 10; pass++) { - if (fsck(pass)) - break; - } - /* * Mount base file system, kernel is assumed to run devtmpfs for /dev */ @@ -263,6 +255,14 @@ int main(int argc, char* argv[]) mount("none", "/proc/bus/usb", "usbfs", 0, NULL); mount("none", "/sys", "sysfs", 0, NULL); + /* + * Check file filesystems in /etc/fstab + */ + for (int pass = 1; pass < 10; pass++) { + if (fsck(pass)) + break; + } + /* * Some non-embedded systems without an initramfs may not have /dev mounted yet * If they do, check if system has udevadm and perform cleanup from initramfs