This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: can I use chroot() multiple times in one program


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.
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]