annotate toys/chroot.c @ 234:163498bf547b

Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
author Rob Landley <rob@landley.net>
date Sat, 19 Jan 2008 17:43:27 -0600
parents d4176f3f3835
children 064fc1b8b7b1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 193
diff changeset
1 /* vi: set sw=4 ts=4:
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 193
diff changeset
2 *
191
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 *
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 193
diff changeset
5 * Copyright 2007 Rob Landley <rob@landley.net>
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 193
diff changeset
6 *
193
0efba0e70c43 Other chroots fall back to "/bin/sh -i", so add the -i.
Rob Landley <rob@landley.net>
parents: 191
diff changeset
7 * Not in SUSv3.
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 193
diff changeset
8
234
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
9 USE_CHROOT(NEWTOY(chroot, "<1", TOYFLAG_USR|TOYFLAG_SBIN))
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
10
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 193
diff changeset
11 config CHROOT
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 193
diff changeset
12 bool "chroot"
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 193
diff changeset
13 default y
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 193
diff changeset
14 help
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 193
diff changeset
15 usage: chroot NEWPATH [commandline...]
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 193
diff changeset
16
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 193
diff changeset
17 Run command within a new root directory. If no command, run /bin/sh.
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 193
diff changeset
18 */
191
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
19
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
20 #include "toys.h"
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
21
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
22 void chroot_main(void)
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
23 {
193
0efba0e70c43 Other chroots fall back to "/bin/sh -i", so add the -i.
Rob Landley <rob@landley.net>
parents: 191
diff changeset
24 char *binsh[] = {"/bin/sh", "-i", 0};
191
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
25 if (chdir(*toys.optargs) || chroot("."))
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
26 perror_exit("%s", *toys.optargs);
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
27 xexec(toys.optargs[1] ? toys.optargs+1 : binsh);
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
28 }