Change the root directory
#include <unistd.h>
int chroot( const char *path );
- path
- The name of the new root directory.
libc
Use the -l c option to
qcc
to link against this library.
This library is usually included automatically.
The chroot() function causes the path directory
to become the root directory, the starting point for path
searches for path
names beginning with /. The user's working directory is
unaffected.
The .. entry in the root directory is interpreted to
mean the root directory itself.
Thus, you can't use .. to access files outside the subtree
rooted at the root directory.
- 0
- Success.
- -1
- An error occurred;
errno
is set.
- EACCES
- Search permission is denied for a component of path.
- EBADF
- The descriptor isn't valid.
- EFAULT
- The path argument points to an illegal address.
- EINTR
- A signal was caught during the chroot() function.
- EIO
- An I/O error occurred while reading from or writing to the filesystem.
- ELOOP
- Too many symbolic links were encountered in translating path.
- EMULTIHOP
- Components of path require hopping to multiple remote machines,
and the filesystem type doesn't allow it.
- ENAMETOOLONG
- The length of the path argument exceeds
{PATH_MAX}, or the length of a path component exceeds
{NAME_MAX} while {_POSIX_NO_TRUNC} is in
effect.
- ENOENT
- The named directory doesn't exist or is a null pathname.
- ENOLINK
- The path points to a remote machine and the
link to that machine is no longer active.
- ENOTDIR
- Any component of the path name isn't a directory.
- EPERM
- The effective user of the calling process isn't the superuser.
Legacy Unix
Safety: | |
Cancellation point |
No |
Interrupt handler |
No |
Signal handler |
No |
Thread |
Yes |
chdir()