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

RETURN VALUE

35       On  success,  zero is returned.  On error, -1 is returned, and errno is
36       set appropriately.
37

ERRORS

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

CONFORMING TO

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

NOTES

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

SEE ALSO

74       chdir(2), path_resolution(7)
75

COLOPHON

77       This page is part of release 3.25 of the Linux  man-pages  project.   A
78       description  of  the project, and information about reporting bugs, can
79       be found at http://www.kernel.org/doc/man-pages/.
80
81
82
83Linux                             2008-06-23                         CHROOT(2)
Impressum