]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
mount move instead of umount and fix the search for fallback inits
authorHarald Hoyer <harald@redhat.com>
Fri, 6 Mar 2009 10:36:32 +0000 (11:36 +0100)
committerHarald Hoyer <harald@redhat.com>
Fri, 6 Mar 2009 10:53:49 +0000 (11:53 +0100)
chdir to newroot, then mount move instead of umount /dev, /sys, etc.
search for fallback init bins in current dirs

switch_root.c

index 2c10396b3460bc2480e9727c3e83190a68c72271..638a66379cc2aebd78270487be77f7d67b058e12 100644 (file)
@@ -26,6 +26,7 @@
 #include <sys/mount.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/param.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -88,17 +89,17 @@ static char *getKernelCmdLine(void)
        int fd = -1;
        int errnum;
 
-       fd = open("/proc/cmdline", O_RDONLY);
+       fd = open("./proc/cmdline", O_RDONLY);
        if (fd < 0) {
                errnum = errno;
-               fprintf(stderr, "Error: Could not open /proc/cmdline: %m\n");
+               fprintf(stderr, "Error: Could not open ./proc/cmdline: %m\n");
                errno = errnum;
                return NULL;
        }
        
        if (readFD(fd, &cmdline) < 0) {
                errnum = errno;
-               fprintf(stderr, "Error: could not read /proc/cmdline: %m\n");
+               fprintf(stderr, "Error: could not read ./proc/cmdline: %m\n");
                close(fd);
                errno = errnum;
                return NULL;
@@ -146,8 +147,8 @@ static char *getKernelArg(char *arg)
 #define MAX_INIT_ARGS 32
 static int build_init_args(char **init, char ***initargs_out)
 {
-       const char *initprogs[] = { "/sbin/init", "/etc/init",
-                                   "/bin/init", "/bin/sh", NULL };
+       const char *initprogs[] = { "./sbin/init", "./etc/init",
+                                   "./bin/init", "./bin/sh", NULL };
        const char *ignoreargs[] = { "console=", "BOOT_IMAGE=", NULL };
        char *cmdline = NULL;
        char **initargs;
@@ -247,14 +248,13 @@ static void switchroot(const char *newroot)
        int rc;
        int i;
 
-       rc = build_init_args(&init, &initargs);
-       if (rc < 0)
-               return;
-
        for (i = 0; umounts[i] != NULL; i++) {
-               if (umount2(umounts[i], MNT_DETACH) < 0) {
-                       fprintf(stderr, "Error unmounting old %s: %m\n",
-                               umounts[i]);
+               char newmount[PATH_MAX];
+               strcpy(newmount, newroot);
+               strcat(newmount, umounts[i]);
+               if (mount(umounts[i], newmount, NULL, MS_MOVE, NULL) < 0) {
+                       fprintf(stderr, "Error mount moving old %s %s %m\n",
+                               umounts[i], newmount);
                        fprintf(stderr, "Forcing unmount of %s\n", umounts[i]);
                        umount2(umounts[i], MNT_FORCE);
                }
@@ -262,6 +262,10 @@ static void switchroot(const char *newroot)
 
        chdir(newroot);
 
+       rc = build_init_args(&init, &initargs);
+       if (rc < 0)
+               return;
+
        if (mount(newroot, "/", NULL, MS_MOVE, NULL) < 0) {
                errnum = errno;
                fprintf(stderr, "switchroot: mount failed: %m\n");