V8/usr/man/man2/chdir.2
.TH CHDIR 2
.SH NAME
chdir, chroot \- change working or root directory
.SH SYNOPSIS
.B chdir(dirname)
.br
.B char *dirname;
.PP
.B chroot(dirname)
.br
.B char *dirname;
.SH DESCRIPTION
.I Chdir\^
changes the working directory
of the invoking process to
.IR dirname ;
.I chroot\^
changes its root directory.
.PP
The root directory
is the starting point
when searching
for pathnames
beginning with
.RB ` / '.
The working directory is the starting point
for pathnames that don't.
The root directory normally points to the system root,
defined when the system is built.
.IR Login (1)
initially sets the working directory
as specified in the password file,
.IR passwd (5).
.PP
After
.IR chroot ,
it is impossible to name a file
outside the subtree rooted at the current root, provided
that the current directory is located within the subtree
and there are no links pointing outside the subtree
(except for the entry
.RB ` "\|.\^.\|" '
in the root directory).
.PP
.I Chroot\^
may only be used by the super-user.
.SH SEE ALSO
sh(1)
.SH DIAGNOSTICS
Zero is returned if the directory was changed;
\-\^1 is returned if the given pathname
doesn't exist, isn't a directory or can't be
searched, or if
.I chroot\^
is used by other than the super-user.
.SH BUGS
Using
.IR chroot ,
it is quite easy to fool set-\s-1UID\s0 programs about
the contents of the password file (for example).