1CHROOT(2)                  Linux Programmer's Manual                 CHROOT(2)
2
3
4

NAME

6       chroot - change root directory
7

SYNOPSIS

9       #include <unistd.h>
10
11       int chroot(const char *path);
12

DESCRIPTION

14       chroot()  changes  the  root directory to that specified in path.  This
15       directory will be used for pathnames beginning with /.  The root direc‐
16       tory is inherited by all children of the current process.
17
18       Only  a privileged process (Linux: one with the CAP_SYS_CHROOT capabil‐
19       ity) may call chroot(2).
20
21       This call changes an ingredient in the pathname resolution process  and
22       does nothing else.
23
24       This  call does not change the current working directory, so that after
25       the call `.' can be outside the tree rooted at `/'.  In particular, the
26       superuser  can  escape from a `chroot jail' by doing `mkdir foo; chroot
27       foo; cd ..'.
28
29       This call does not close open file descriptors, and such file  descrip‐
30       tors may allow access to files outside the chroot tree.
31

RETURN VALUE

33       On  success,  zero is returned.  On error, -1 is returned, and errno is
34       set appropriately.
35

ERRORS

37       Depending on the file system, other errors can be returned.   The  more
38       general errors are listed below:
39
40       EACCES Search  permission  is denied on a component of the path prefix.
41              (See also path_resolution(2).)
42
43       EFAULT path points outside your accessible address space.
44
45       EIO    An I/O error occurred.
46
47       ELOOP  Too many symbolic links were encountered in resolving path.
48
49       ENAMETOOLONG
50              path is too long.
51
52       ENOENT The file does not exist.
53
54       ENOMEM Insufficient kernel memory was available.
55
56       ENOTDIR
57              A component of path is not a directory.
58
59       EPERM  The caller has insufficient privilege.
60

CONFORMING TO

62       SVr4, 4.4BSD, SUSv2 (marked LEGACY).  This  function  is  not  part  of
63       POSIX.1-2001.
64

NOTES

66       A  child  process created via fork(2) inherits its parent's root direc‐
67       tory.  The root directory is left unchanged by execve(2).
68
69       FreeBSD has a stronger jail() system call.
70

SEE ALSO

72       chdir(2), path_resolution(2)
73
74
75
76Linux 2.6.7                       2004-06-23                         CHROOT(2)
Impressum