This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: can I use chroot() multiple times in one program
- From: AmÃrico Wang <xiyou dot wangcong at gmail dot com>
- To: Wu Zhou <woodzltc at gmail dot com>
- Cc: libc-help at sourceware dot org
- Date: Tue, 12 Jan 2010 23:59:03 +0800
- Subject: Re: can I use chroot() multiple times in one program
- References: <4e8ba5bf1001120751s4cb74875iaed58ca731c97f3@mail.gmail.com>
On Tue, Jan 12, 2010 at 10:51:14AM -0500, Wu Zhou wrote:
>Hello all,
>
>I have a question about the usage of chroot(). Could I do something like this:
>
> chroot("/chroot");
> do_something();
>
> chroot("/"); // want the root directory back to "/"
> do_something();
No, this is one-direction way, never comes back...
>
> chroot("/chroot");
> do_something();
>
>I had a try, after the second chroot("/"), I use system() to call a
>python script in the original root directoy, it reports that
>
>sh: /tmp/python-script: not found
>
>But in fact, I can see this script in the original root directory:
>
> # ls -l -l /tmp/python-script
>-rwxr-xr-x 1 root root 4419 Jan 12 10:51 /tmp/python-script
>
>The second chroot session is like this:
>
> chroot("/");
> system("/tmp/python-script");
>
>Anyone can hint me what is the problem?
>
chroot is a jail, once you jump into it, you can't jump out.
The problem is why do you want that?
--
Live like a child, think like the god.