chroot()

NAME

chroot() - change root directory

SYNOPSIS

#include <unistd.h>

int chroot(const char *directory)

DESCRIPTION

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

RETURN VALUES

The chroot(2) call returns 0 for success, and -1 if an error occurred. It sets errno to indicate the cause of the error.

ERRORS

The chroot(2) call can fail for the following reasons:

[EACCES]
The process does not have search permission on some component of directory.
[ELOOP]
Too many symbolic links were encountered.
[ENAMETOOLONG]
The directory is longer than {PATH_MAX} or a component is longer than {NAME_MAX}, or when resolving symbolic links, an intermediate version of the name was longer than {PATH_MAX}.
[ENOENT]
Either directory is an empty string, or some component of it doesn't exist.
[ENOTDIR]
Some component of directory isn't a directory.
[EPERM]
The effective user ID of the process does not have the privileges to change the root directory.

NOTES

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.