OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man2 / chroot.2
1 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Modified by Michael Haardt <michael@moria.de>
26 .\" Modified 1993-07-21 by Rik Faith <faith@cs.unc.edu>
27 .\" Modified 1994-08-21 by Michael Chastain <mec@shell.portal.com>
28 .\" Modified 1996-06-13 by aeb
29 .\" Modified 1996-11-06 by Eric S. Raymond <esr@thyrsus.com>
30 .\" Modified 1997-08-21 by Joseph S. Myers <jsm28@cam.ac.uk>
31 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
32 .\"
33 .TH CHROOT 2 2010-09-20 "Linux" "Linux Programmer's Manual"
34 .SH NAME
35 chroot \- change root directory
36 .SH SYNOPSIS
37 .B #include <unistd.h>
38 .sp
39 .BI "int chroot(const char *" path );
40 .sp
41 .in -4n
42 Feature Test Macro Requirements for glibc (see
43 .BR feature_test_macros (7)):
44 .in
45 .sp
46 .BR chroot ():
47 .ad l
48 .RS 4
49 .PD 0
50 .TP 4
51 Since glibc 2.2.2:
52 .nf
53 _BSD_SOURCE ||
54     (_XOPEN_SOURCE\ >=\ 500 ||
55         _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED) &&
56     !(_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600)
57 .TP 4
58 .fi
59 Before glibc 2.2.2: none
60 .PD
61 .RE
62 .ad b
63 .SH DESCRIPTION
64 .BR chroot ()
65 changes the root directory of the calling process to that specified in
66 .IR path .
67 This directory will be used for pathnames beginning with \fI/\fP.
68 The root directory is inherited by all children of the calling process.
69
70 Only a privileged process (Linux: one with the
71 .B CAP_SYS_CHROOT
72 capability) may call
73 .BR chroot ().
74
75 This call changes an ingredient in the pathname resolution process
76 and does nothing else.
77
78 This call does not change the current working directory,
79 so that after the call \(aq\fI.\fP\(aq can
80 be outside the tree rooted at \(aq\fI/\fP\(aq.
81 In particular, the superuser can escape from a "chroot jail"
82 by doing:
83 .nf
84
85     mkdir foo; chroot foo; cd ..
86 .fi
87
88 This call does not close open file descriptors, and such file
89 descriptors may allow access to files outside the chroot tree.
90 .SH RETURN VALUE
91 On success, zero is returned.
92 On error, \-1 is returned, and
93 .I errno
94 is set appropriately.
95 .SH ERRORS
96 Depending on the filesystem, other errors can be returned.
97 The more general errors are listed below:
98 .TP
99 .B EACCES
100 Search permission is denied on a component of the path prefix.
101 (See also
102 .BR path_resolution (7).)
103 .\" Also search permission is required on the final component,
104 .\" maybe just to guarantee that it is a directory?
105 .TP
106 .B EFAULT
107 .I path
108 points outside your accessible address space.
109 .TP
110 .B EIO
111 An I/O error occurred.
112 .TP
113 .B ELOOP
114 Too many symbolic links were encountered in resolving
115 .IR path .
116 .TP
117 .B ENAMETOOLONG
118 .I path
119 is too long.
120 .TP
121 .B ENOENT
122 The file does not exist.
123 .TP
124 .B ENOMEM
125 Insufficient kernel memory was available.
126 .TP
127 .B ENOTDIR
128 A component of
129 .I path
130 is not a directory.
131 .TP
132 .B EPERM
133 The caller has insufficient privilege.
134 .SH CONFORMING TO
135 SVr4, 4.4BSD, SUSv2 (marked LEGACY).
136 This function is not part of POSIX.1-2001.
137 .\" SVr4 documents additional EINTR, ENOLINK and EMULTIHOP error conditions.
138 .\" X/OPEN does not document EIO, ENOMEM or EFAULT error conditions.
139 .SH NOTES
140 A child process created via
141 .BR fork (2)
142 inherits its parent's root directory.
143 The root directory is left unchanged by
144 .BR execve (2).
145
146 FreeBSD has a stronger
147 .BR jail ()
148 system call.
149 .\" FIXME . eventually say something about containers,
150 .\" virtual servers, etc.?
151 .SH SEE ALSO
152 .BR chdir (2),
153 .BR path_resolution (7)
154 .SH COLOPHON
155 This page is part of release 3.79 of the Linux
156 .I man-pages
157 project.
158 A description of the project,
159 information about reporting bugs,
160 and the latest version of this page,
161 can be found at
162 \%http://www.kernel.org/doc/man\-pages/.