]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
switch_root: fork before cleaning up the filesystem.
authorPeter Jones <pjones@redhat.com>
Fri, 19 Jun 2009 19:21:59 +0000 (15:21 -0400)
committerKarel Zak <kzak@redhat.com>
Mon, 22 Jun 2009 19:45:25 +0000 (21:45 +0200)
Fork before cleaning up the old filesystem, so it becomes asyncronous,
which results in a faster boot time.

Signed-off-by: Peter Jones <pjones@redhat.com>
sys-utils/switch_root.c

index 75725e707277ed08f3955b722246811a10f04c68..1de3a2e58cf3fb53c91407190eae493dcf803c55 100644 (file)
@@ -114,6 +114,7 @@ static int switchroot(const char *newroot)
        const char *umounts[] = { "/dev", "/proc", "/sys", NULL };
        int i;
        int cfd;
+       pid_t pid;
 
        for (i = 0; umounts[i] != NULL; i++) {
                char newmount[PATH_MAX];
@@ -135,7 +136,12 @@ static int switchroot(const char *newroot)
 
        cfd = open("/", O_RDONLY);
        if (cfd >= 0) {
-               recursiveRemove(cfd);
+               pid = fork();
+               if (pid <= 0) {
+                       recursiveRemove(cfd);
+                       if (pid == 0)
+                               exit(EXIT_SUCCESS);
+               }
                close(cfd);
        }