annotate toys/chroot.c @ 193:0efba0e70c43

Other chroots fall back to "/bin/sh -i", so add the -i.
author Rob Landley <rob@landley.net>
date Mon, 03 Dec 2007 20:05:14 -0600
parents 7f55c59f5122
children d4176f3f3835
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.
193
0efba0e70c43 Other chroots fall back to "/bin/sh -i", so add the -i.
Rob Landley <rob@landley.net>
parents: 191
diff changeset
4 *
0efba0e70c43 Other chroots fall back to "/bin/sh -i", so add the -i.
Rob Landley <rob@landley.net>
parents: 191
diff changeset
5 * Not in SUSv3.
191
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
6 */
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
7
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
8 #include "toys.h"
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
9
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
10 void chroot_main(void)
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
11 {
193
0efba0e70c43 Other chroots fall back to "/bin/sh -i", so add the -i.
Rob Landley <rob@landley.net>
parents: 191
diff changeset
12 char *binsh[] = {"/bin/sh", "-i", 0};
191
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
13 if (chdir(*toys.optargs) || chroot("."))
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
14 perror_exit("%s", *toys.optargs);
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
15 xexec(toys.optargs[1] ? toys.optargs+1 : binsh);
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
16 }