From e16a6ad4f024969f689908e0fda8efbdceb932da Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sun, 26 Apr 2020 15:04:56 +0200 Subject: [PATCH] Check if /sys exists and only mount if /sys isn't already mounted Signed-off-by: Joachim Nilsson --- src/finit.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/finit.c b/src/finit.c index 384127b6..800971a7 100644 --- a/src/finit.c +++ b/src/finit.c @@ -290,7 +290,7 @@ int main(int argc, char *argv[]) uev_ctx_t loop; char cmd[256]; char *path; - int rc; + int rc = 0; /* * finit/init/telinit client tool uses /dev/initctl pipe @@ -352,8 +352,6 @@ int main(int argc, char *argv[]) */ if (mount("none", "/proc", "proc", 0, NULL)) _pe("Failed mounting /proc"); - if (mount("none", "/sys", "sysfs", 0, NULL)) - _pe("Failed mounting /sys"); if (fisdir("/proc/bus/usb")) mount("none", "/proc/bus/usb", "usbfs", 0, NULL); @@ -404,7 +402,7 @@ int main(int argc, char *argv[]) if (!rc) print(1, "Cannot remount / as read-write, fsck failed before"); else - run_interactive("mount -n -o remount,rw /", "Remounting / as read-write"); + rc = run_interactive("mount -n -o remount,rw /", "Remounting / as read-write"); } break; } @@ -416,10 +414,20 @@ int main(int argc, char *argv[]) * XXX: Untested, in the initramfs age we should * probably use switch_root instead. */ - mount(SYSROOT, "/", NULL, MS_MOVE, NULL); + rc = mount(SYSROOT, "/", NULL, MS_MOVE, NULL); #endif } + /* Create /sys if missing, some systems don't include it in their rootfs skeleton */ + if (!rc && !fisdir("/sys")) + mkdir("/sys", 0755); + + /* Only mount /sys if it's not already mounted */ + if (!fismnt("/sys") && mount("none", "/sys", "sysfs", 0, NULL)) { + print(1, "Cannot mount /sys, your system may behave unusually"); + _pe("Failed mounting /sys"); + } + /* * Initialize .conf system and load static /etc/finit.conf * Also initializes global_rlimit[] for udevd, below.