[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

chroot for busybox



Here is a patch to add a chroot command to busybox.
This can be useful in the rescue disk because it allows
running commands from the target (and maybe sometime
continue installation without rebooting?)

lupus

-- 
"The number of UNIX installations has grown to 10, with more expected."
    - _The UNIX Programmer's Manual_, Second Edition, June, 1972.
? busybox.links
? chroot.diff
Index: busybox.def.h
===================================================================
RCS file: /debian/home/sr1/lib/cvs/boot-floppies/utilities/busybox/busybox.def.h,v
retrieving revision 1.2
diff -u -r1.2 busybox.def.h
--- busybox.def.h	1998/11/26 23:51:59	1.2
+++ busybox.def.h	1999/01/19 11:31:55
@@ -8,6 +8,7 @@
 #define BB_CHGRP
 #define BB_CHMOD
 #define BB_CHOWN
+#define BB_CHROOT
 #define BB_CLEAR
 #define BB_CP
 #define BB_DATE
Index: chroot.c
===================================================================
RCS file: chroot.c
diff -N chroot.c
--- /dev/null	Sun Oct 12 13:38:15 1997
+++ chroot.c	Tue Jan 19 05:31:55 1999
@@ -0,0 +1,28 @@
+#include "internal.h"
+#include <stdio.h>
+#include <unistd.h>
+
+
+const char	chroot_usage[] = "chroot directory [command]\n"
+	"Run a command with special root directory.\n";
+
+extern int
+chroot_main(struct FileInfo * i, int argc, char * * argv)
+{
+	char* prog;
+
+	if ( chroot(argv[1]) ) {
+		name_and_error("cannot chroot to that directory");
+		return 1;
+	}
+	if ( argc > 2 ) {
+		execvp(argv[2], argv+2);
+	} else {
+		prog = getenv("SHELL");
+		if (!prog)
+			prog = "/bin/sh";
+		execlp(prog, prog, NULL);
+	}
+	name_and_error("cannot exec");
+	return 1;
+}
Index: internal.h
===================================================================
RCS file: /debian/home/sr1/lib/cvs/boot-floppies/utilities/busybox/internal.h,v
retrieving revision 1.9
diff -u -r1.9 internal.h
--- internal.h	1999/01/09 20:40:27	1.9
+++ internal.h	1999/01/19 11:31:55
@@ -64,6 +64,7 @@
 extern int chgrp_main(struct FileInfo * i, int argc, char * * argv);
 extern int chmod_main(struct FileInfo * i, int argc, char * * argv);
 extern int chown_main(struct FileInfo * i, int argc, char * * argv);
+extern int chroot_main(struct FileInfo * i, int argc, char * * argv);
 extern int clear_main(struct FileInfo * i, int argc, char * * argv);
 extern int date_main(struct FileInfo * i, int argc, char * * argv);
 extern int dd_main(struct FileInfo * i, int argc, char * * argv);
@@ -141,6 +142,7 @@
 extern const char	chgrp_usage[];
 extern const char	chmod_usage[];
 extern const char	chown_usage[];
+extern const char	chroot_usage[];
 extern const char	clear_usage[];
 extern const char	cp_usage[];
 extern const char	date_usage[];
Index: main.c
===================================================================
RCS file: /debian/home/sr1/lib/cvs/boot-floppies/utilities/busybox/main.c,v
retrieving revision 1.8
diff -u -r1.8 main.c
--- main.c	1999/01/09 20:40:28	1.8
+++ main.c	1999/01/19 11:31:55
@@ -20,6 +20,9 @@
 #ifdef BB_CHOWN	//bin
 { "chown",	chown_main, 0, chown_usage,			2, -1 },
 #endif
+#ifdef BB_CHROOT //sbin
+{ "chroot",	chroot_main, 0, chroot_usage,			1, -1 },
+#endif
 #ifdef BB_CLEAR	//usr/bin
 { "clear",	clear_main, 0, clear_usage,			0, 0 },
 #endif

Reply to: