POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR(3C) Standard C Library Functions
NAME
posix_spawn_file_actions_addchdir,
posix_spawn_file_actions_addfchdir -
add directory changing actions to a spawn file actions object
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <spawn.h> int posix_spawn_file_actions_addchdir(
posix_spawn_file_actions_t *restrict file_actions,
const char *restrict path);
int posix_spawn_file_actions_addfchdir(
posix_spawn_file_actions_t *restrict file_actions,
int fd);
DESCRIPTION
The
posix_spawn_file_actions_addchdir() and
posix_spawn_file_actions_addfchdir() functions add an action to change
the spawned process's current working directory to the spawn file
actions object,
file_actions. The
posix_spawn_file_actions_addchdir()
function will cause the spawned process to call
chdir(2) on
path, while
the
posix_spawn_file_actions_addfchdir() function will cause the
spawned process to call
fchdir(2) on
fd.
Actions are resolved in the order that they are added. This implies
that if
posix_spawn_file_actions_addchdir() is called with a relative
path, it will be evaluated based on any other actions that the process
has already taken. Similarly, if the
posix_spawn_file_actions_addfchdir() function is passed a file
descriptor that a prior action has closed
(
posix_spawn_file_actions_addclose(3C)), opened over
(
posix_spawn_file_actions_addopen(3C)), or duplicated over
(
posix_spawn_file_actions_adddup2(3C)), then the
fchdir(2) call will
use the new file descriptor. This may cause the call to fail, because
fd no longer refers to a directory, or cause the process to change to a
different directory than originally expected.
The
posix_spawn_file_actions_addchdir() function will duplicate the
string
path, allowing the caller to release any storage associated with
it following the function returning. It does not need to be persisted.
RETURN VALUES
Upon successful completion, the
posix_spawn_file_actions_addchdir() and
posix_spawn_file_actions_addfchdir() functions return
0 and record the
corresponding file action. Otherwise, an error number will be
returned.
ERRORS
The
posix_spawn_file_actions_addchdir() and
posix_spawn_file_actions_addfchdir() functions will fail if:
ENOMEM Insufficient memory exists to add the spawn file
actions object.
Additionally, the
posix_spawn_file_actions_addfchdir() function will
fail if:
EBADF The file descriptor,
fd, is negative or an otherwise
invalid file descriptor.
INTERFACE STABILITY
CommittedMT-LEVEL MT-SafeSEE ALSO
chdir(2),
fchdir(2),
posix_spawn(3C),
posix_spawn_file_actions_addclose(3C),
posix_spawn_file_actions_adddup(3C),
posix_spawn_file_actions_addopen(3C),
posix_spawn_file_actions_init(3C)illumos January 5, 2025 illumos