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 Wed, Jan 13, 2010 at 12:10 AM, Wu Zhou <woodzltc@gmail.com> wrote:
> 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?

True, you can find it in task_struct ->fs->root.
But this doesn't mean you can go back.

> 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.
>

Well, suppose you have a program within the chroot jail which also
does a chroot(), so with _your_ design it can jump out the jail!! With
the correct design, it can't, never.

>>
>> 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. :-)
>

Not sure if you have Python environment within your chroot jail,
and if your chroot directory is on the same file system with your
python script, you can try to make a hard link to that python script.


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