aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2005-12-20 17:25:51 +0000
committerlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2005-12-20 17:25:51 +0000
commit2300f6524a98bcc72522eb0b3697580fca3ba62c (patch)
tree03bda36e6ef91ece33c5bfc2d3c7a64a599f6b94
parent7e8e07b9434c750fb269041cd40a1e093952ded0 (diff)
downloadbusybox-w32-2300f6524a98bcc72522eb0b3697580fca3ba62c.tar.gz
busybox-w32-2300f6524a98bcc72522eb0b3697580fca3ba62c.tar.bz2
busybox-w32-2300f6524a98bcc72522eb0b3697580fca3ba62c.zip
Fix chroot, leave console alone if -c not specified, and yank debug code.
(I still haven't set up a test environment to confirm this works...) git-svn-id: svn://busybox.net/trunk/busybox@12960 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--util-linux/switch_root.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/util-linux/switch_root.c b/util-linux/switch_root.c
index 242699560..0c86eec08 100644
--- a/util-linux/switch_root.c
+++ b/util-linux/switch_root.c
@@ -56,17 +56,17 @@ static void delete_contents(char *directory)
56 closedir(dir); 56 closedir(dir);
57 57
58 // Directory should now be empty. Zap it. 58 // Directory should now be empty. Zap it.
59 printf("rmdir %s\n",directory); // rmdir(directory); 59 rmdir(directory);
60 } 60 }
61 61
62 // It wasn't a directory. Zap it. 62 // It wasn't a directory. Zap it.
63 63
64 } else printf("unlink %s\n",directory); //unlink(directory); 64 } else unlink(directory);
65} 65}
66 66
67int switch_root_main(int argc, char *argv[]) 67int switch_root_main(int argc, char *argv[])
68{ 68{
69 char *newroot, *console="/dev/console"; 69 char *newroot, *console=NULL;
70 struct stat st1, st2; 70 struct stat st1, st2;
71 struct statfs stfs; 71 struct statfs stfs;
72 72
@@ -98,19 +98,24 @@ int switch_root_main(int argc, char *argv[])
98 } 98 }
99 99
100 // Zap everything out of rootdev 100 // Zap everything out of rootdev
101
101 delete_contents("/"); 102 delete_contents("/");
102 103
103 // Overmount / with newdir 104 // Overmount / with newdir and chroot into it. The chdir is needed to
105 // recalculate "." and ".." links.
104 106
105 if (mount(".", "/", NULL, MS_MOVE, NULL) || chdir("/")) 107 if (mount(".", "/", NULL, MS_MOVE, NULL) || chroot(".") || chdir("/"))
106 bb_error_msg_and_die("moving root"); 108 bb_error_msg_and_die("moving root");
107 109
108 // Reopen stdin/stdout/stderr to /dev/console 110 // If a new console specified, redirect stdin/stdout/stderr to that.
109 close(0); 111
110 if(open(console, O_RDWR) < 0) 112 if (console) {
111 bb_error_msg_and_die("Bad console '%s'",console); 113 close(0);
112 dup2(0, 1); 114 if(open(console, O_RDWR) < 0)
113 dup2(0, 2); 115 bb_error_msg_and_die("Bad console '%s'",console);
116 dup2(0, 1);
117 dup2(0, 2);
118 }
114 119
115 // Exec real init. (This is why we must be pid 1.) 120 // Exec real init. (This is why we must be pid 1.)
116 execv(argv[optind],argv+optind+1); 121 execv(argv[optind],argv+optind+1);