svn commit: trunk/busybox/util-linux

vda at busybox.net vda at busybox.net
Wed Apr 18 21:40:31 UTC 2007


Author: vda
Date: 2007-04-18 14:40:30 -0700 (Wed, 18 Apr 2007)
New Revision: 18493

Log:
switch_root: error_msg -> perror_msg, reduce by 22 bytes while at it.


Modified:
   trunk/busybox/util-linux/switch_root.c


Changeset:
Modified: trunk/busybox/util-linux/switch_root.c
===================================================================
--- trunk/busybox/util-linux/switch_root.c	2007-04-18 21:14:46 UTC (rev 18492)
+++ trunk/busybox/util-linux/switch_root.c	2007-04-18 21:40:30 UTC (rev 18493)
@@ -75,14 +75,14 @@
 
 	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 @@
 	// 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 @@
 	}
 
 	// 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]);
 }




More information about the busybox-cvs mailing list