can I use chroot() multiple times in one program

Wu Zhou woodzltc@gmail.com
Tue Jan 12 16:10:00 GMT 2010


On Tue, Jan 12, 2010 at 10:59 AM, Américo Wang <xiyou.wangcong@gmail.com> wrote:
> 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...
>

Ah. Sound a little odd to me. AFAIK, chroot is a system call, which
append the named directory to the path resolution for this process and
its children. Maybe this directory is saved some place in the process
control block? Another chroot should be able to change this again and
the later code will use the new directory. Don't see why this is not
designed in such a way.

>
> chroot is a jail, once you jump into it, you can't jump out.
> The problem is why do you want that?

I have a large piece of legacy C code, working on a chrooted
environment. and we have a python script to replace one part of this C
code, which need to look at this chroot environment back in the
original root directory. And I am just lazy, don't want to use some
kind of IPC mechanism at this time. :-)

Thanks and Best Regards
Wu Zhou



More information about the Libc-help mailing list