1 .\" $NetBSD: chroot.2,v 1.23 2010/05/31 12:16:20 njoly Exp $
3 .\" Copyright (c) 1983, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)chroot.2 8.1 (Berkeley) 6/4/93
37 .Nd change root directory
43 .Fn chroot "const char *dirname"
48 is the address of the pathname of a directory, terminated by an ASCII NUL.
52 to become the root directory,
53 that is, the starting point for path searches of pathnames
57 In order for a directory to become the root directory
58 a process must have execute (search) access for that directory.
60 If the current working directory is not at or under the new root
61 directory, it is silently set to the new root directory.
62 It should be noted that, on most other systems,
64 has no effect on the process's current directory.
66 This call is restricted to the super-user.
70 function performs the same operation on an open directory file
71 known by the file descriptor
74 Upon successful completion, a value of 0 is returned.
75 Otherwise, a value of \-1 is returned and
77 is set to indicate an error.
80 will fail and the root directory will be unchanged if:
83 A component of the path name is not a directory.
84 .It Bq Er ENAMETOOLONG
85 A component of a pathname exceeded
87 characters, or an entire path name exceeded
91 The named directory does not exist.
93 Search permission is denied for any component of the path name.
95 Too many symbolic links were encountered in translating the pathname.
98 points outside the process's allocated address space.
100 An I/O error occurred while reading from or writing to the file system.
102 The effective user ID of the calling process is not the super-user.
106 will fail and the root directory will be unchanged if:
109 Search permission is denied for the directory referenced
110 by the file descriptor.
114 is not a valid file descriptor.
116 An I/O error occurred while reading from or writing to the file system.
120 does not reference a directory.
122 The effective user ID of the calling process is not the super-user.
131 with the restriction that the calling process' working directory must be at
132 or under the new root directory.
133 Otherwise, the working directory is silently set to the new root directory;
134 this is an extension to the standard.
137 was declared a legacy interface, and subsequently removed in
142 function call appeared in
144 Working directory handling was changed in
146 to prevent one way a process could use a second
148 call to a different directory to "escape" from the restricted subtree.