annotate toys/other/chroot.c @ 656:6df4ccc0acbe

Regularize command headers, update links to standards documents.
author Rob Landley <rob@landley.net>
date Sat, 25 Aug 2012 18:08:51 -0500
parents 2986aa63a021
children 786841fdb1e0
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
312
064fc1b8b7b1 Chroot should stop option parsing at the first non-option argument.
Rob Landley <rob@landley.net>
parents: 234
diff changeset
7 USE_CHROOT(NEWTOY(chroot, "^<1", TOYFLAG_USR|TOYFLAG_SBIN))
234
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
8
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 193
diff changeset
9 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
10 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
11 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
12 help
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 193
diff changeset
13 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
14
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 193
diff changeset
15 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
16 */
191
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
17
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
18 #include "toys.h"
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
19
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
20 void chroot_main(void)
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
21 {
193
0efba0e70c43 Other chroots fall back to "/bin/sh -i", so add the -i.
Rob Landley <rob@landley.net>
parents: 191
diff changeset
22 char *binsh[] = {"/bin/sh", "-i", 0};
191
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
23 if (chdir(*toys.optargs) || chroot("."))
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
24 perror_exit("%s", *toys.optargs);
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
25 xexec(toys.optargs[1] ? toys.optargs+1 : binsh);
7f55c59f5122 Add chroot.
Rob Landley <rob@landley.net>
parents:
diff changeset
26 }