summaryrefslogtreecommitdiff
path: root/util-linux/switch_root.c
diff options
context:
space:
mode:
authorDenis Vlasenko2007-04-18 21:40:30 +0000
committerDenis Vlasenko2007-04-18 21:40:30 +0000
commit3ace9fa6d8f40886855458759455ecb9f16a6f12 (patch)
tree9a701159f860353116347a7abf33f4656c8b0164 /util-linux/switch_root.c
parent088b959d00a5df6e0d9436d6e3aec20458774ebc (diff)
downloadbusybox-3ace9fa6d8f40886855458759455ecb9f16a6f12.zip
busybox-3ace9fa6d8f40886855458759455ecb9f16a6f12.tar.gz
switch_root: error_msg -> perror_msg, reduce by 22 bytes while at it.
Diffstat (limited to 'util-linux/switch_root.c')
-rw-r--r--util-linux/switch_root.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/util-linux/switch_root.c b/util-linux/switch_root.c
index 6dba9f0..88bb9db 100644
--- a/util-linux/switch_root.c
+++ b/util-linux/switch_root.c
@@ -75,14 +75,14 @@ int switch_root_main(int argc, char **argv)
opt_complementary = "-2";
getopt32(argc, argv, "c:", &console);
+ argv += optind;
// Change to new root directory and verify it's a different fs.
- newroot = argv[optind++];
+ newroot = *argv++;
- if (chdir(newroot) || lstat(".", &st1) || lstat("/", &st2) ||
- st1.st_dev == st2.st_dev)
- {
+ xchdir(newroot);
+ if (lstat(".", &st1) || lstat("/", &st2) || st1.st_dev == st2.st_dev) {
bb_error_msg_and_die("bad newroot %s", newroot);
}
rootdev = st2.st_dev;
@@ -105,8 +105,9 @@ int switch_root_main(int argc, char **argv)
// Overmount / with newdir and chroot into it. The chdir is needed to
// recalculate "." and ".." links.
- if (mount(".", "/", NULL, MS_MOVE, NULL) || chroot(".") || chdir("/"))
+ if (mount(".", "/", NULL, MS_MOVE, NULL) || chroot("."))
bb_error_msg_and_die("error moving root");
+ xchdir("/");
// If a new console specified, redirect stdin/stdout/stderr to that.
@@ -118,6 +119,6 @@ int switch_root_main(int argc, char **argv)
}
// Exec real init. (This is why we must be pid 1.)
- execv(argv[optind], argv+optind);
- bb_error_msg_and_die("bad init '%s'", argv[optind]);
+ execv(argv[0], argv);
+ bb_perror_msg_and_die("bad init %s", argv[0]);
}