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
13   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
14
15       chroot():
16           Since glibc 2.2.2:
17               _BSD_SOURCE ||
18                   (_XOPEN_SOURCE >= 500 ||
19                       _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) &&
20                   !(_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
21           Before glibc 2.2.2: none
22

DESCRIPTION

24       chroot()  changes  the  root  directory  of the calling process to that
25       specified in path.  This directory will be used for pathnames beginning
26       with /.  The root directory is inherited by all children of the calling
27       process.
28
29       Only a privileged process (Linux: one with the CAP_SYS_CHROOT  capabil‐
30       ity) may call chroot().
31
32       This  call changes an ingredient in the pathname resolution process and
33       does nothing else.
34
35       This call does not change the current working directory, so that  after
36       the call '.' can be outside the tree rooted at '/'.  In particular, the
37       superuser can escape from a "chroot jail" by doing:
38
39           mkdir foo; chroot foo; cd ..
40
41       This call does not close open file descriptors, and such file  descrip‐
42       tors may allow access to files outside the chroot tree.
43

RETURN VALUE

45       On  success,  zero is returned.  On error, -1 is returned, and errno is
46       set appropriately.
47

ERRORS

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

CONFORMING TO

74       SVr4, 4.4BSD, SUSv2 (marked LEGACY).  This  function  is  not  part  of
75       POSIX.1-2001.
76

NOTES

78       A  child  process created via fork(2) inherits its parent's root direc‐
79       tory.  The root directory is left unchanged by execve(2).
80
81       FreeBSD has a stronger jail() system call.
82

SEE ALSO

84       chdir(2), path_resolution(7)
85

COLOPHON

87       This page is part of release 3.53 of the Linux  man-pages  project.   A
88       description  of  the project, and information about reporting bugs, can
89       be found at http://www.kernel.org/doc/man-pages/.
90
91
92
93Linux                             2010-09-20                         CHROOT(2)
Impressum