]> err.no Git - systemd/commitdiff
core/main.c: do_switch_root(): do not remove the old root if not in initrd
authorHarald Hoyer <harald@redhat.com>
Wed, 16 May 2012 12:22:43 +0000 (14:22 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 21 May 2012 16:50:29 +0000 (18:50 +0200)
Only recursively remove the old root, if we have been in an
initrd/initramfs.

src/core/main.c

index 747121461d0568414d835db5cbb1515e01bd1501..d7143edae2b5d062c51df61872fd3b0f8cab8897 100644 (file)
@@ -1180,6 +1180,7 @@ static int do_switch_root(const char *switch_root) {
         int i;
         int cfd = -1;
         struct stat switch_root_stat, sb;
+        bool remove_old_root;
 
         if (path_equal(switch_root, "/"))
                 return 0;
@@ -1190,6 +1191,8 @@ static int do_switch_root(const char *switch_root) {
                 goto fail;
         }
 
+        remove_old_root = in_initrd();
+
         for (i = 0; umounts[i] != NULL; i++) {
                 char newmount[PATH_MAX];
 
@@ -1215,7 +1218,8 @@ static int do_switch_root(const char *switch_root) {
                 goto fail;
         }
 
-        cfd = open("/", O_RDONLY);
+        if (remove_old_root)
+                cfd = open("/", O_RDONLY);
 
         if (mount(switch_root, "/", NULL, MS_MOVE, NULL) < 0) {
                 r = -errno;