annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
191
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
1 /* vi: set sw=4 ts=4: */
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
2 /*
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * chroot.c - Run command in new root directory.
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
4 */
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
5
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
6 #include "toys.h"
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
7
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
8 void chroot_main(void)
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
9 {
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
10 char *binsh[] = {"/bin/sh", 0};
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
11 if (chdir(*toys.optargs) || chroot("."))
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
12 perror_exit("%s", *toys.optargs);
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
13 xexec(toys.optargs[1] ? toys.optargs+1 : binsh);
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
14 }