diff toys/chroot.c @ 191:7f55c59f5122

Add chroot.
author Rob Landley <rob@landley.net>
date Mon, 03 Dec 2007 19:28:51 -0600
parents
children 0efba0e70c43
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/toys/chroot.c	Mon Dec 03 19:28:51 2007 -0600
@@ -0,0 +1,14 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * chroot.c - Run command in new root directory.
+ */
+
+#include "toys.h"
+
+void chroot_main(void)
+{
+	char *binsh[] = {"/bin/sh", 0};
+	if (chdir(*toys.optargs) || chroot("."))
+		perror_exit("%s", *toys.optargs);
+	xexec(toys.optargs[1] ? toys.optargs+1 : binsh);
+}