Mercurial > hg > toybox
annotate toys/chroot.c @ 272:a5652aa22f38
Another cp -r fix, another test case...
author | Rob Landley <rob@landley.net> |
---|---|
date | Wed, 26 Mar 2008 00:54:56 -0500 |
parents | 163498bf547b |
children | 064fc1b8b7b1 |
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 | 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 | 19 |
20 #include "toys.h" | |
21 | |
22 void chroot_main(void) | |
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 | 25 if (chdir(*toys.optargs) || chroot(".")) |
26 perror_exit("%s", *toys.optargs); | |
27 xexec(toys.optargs[1] ? toys.optargs+1 : binsh); | |
28 } |