chroot() - change root directory
#include <unistd.h>
int chroot(const char *directory)
The chroot(2) call makes the directory named by directory the root for the calling process and its children. That is, pathnames beginning with "/" are taken as relative to directory.
Note that calling chroot(2) with the argument / has no effect; a single-character-long directory argument is ignored, and the function returns.
Note that if the current working directory is not in the subtree depending from directory, the calling process can still get access to directories outside of the chroot(2) prison by using relative pathnames.
Once the current working directory is in the subtree depending from directory, relative pathnames will no longer refer to directories outside the chroot(2) prison. Inside the chroot(2) prison, the pathname .. is taken to mean root.
Symbolic links will be interpreted in the context of the current root.
The traditional way to escape from a chroot(2) prison is to store the file descriptor for the directory / and use the fchroot() call to escape. The Interix subsystem does not support fchroot().
The chroot(2) call returns 0 for success, and -1 if an error occurred. It sets errno to indicate the cause of the error.
The chroot(2) call can fail for the following reasons:
Once a process has used chroot(2), it is no longer allowed to exec Win32 processes. This is done because the Win32 programs will not respect the new value for the root directory.