chroot()

Change the root directory

Synopsis:

#include <unistd.h>

int chroot( const char *path );

Arguments:

path
The name of the new root directory. This can include a network root (e.g. /net/ node_name).

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

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.

In order to change the root directory, your process must have the PROCMGR_AID_CHROOT ability enabled. For more information, see procmgr_ability() .

Returns:

0
Success.
-1
An error occurred; errno is set.

Errors:

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.

Classification:

Legacy Unix

Safety:  
Cancellation point No
Interrupt handler No
Signal handler No
Thread Yes

Last modified: 2013-12-23

comments powered by Disqus