can I use chroot() multiple times in one program

Wu Zhou woodzltc@gmail.com
Tue Jan 12 15:51:00 GMT 2010


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();

  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?

Thanks and Best Regards
Wu Zhou



More information about the Libc-help mailing list