POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR(3C) Standard C Library Functions POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR(3C)

posix_spawn_file_actions_addchdir, posix_spawn_file_actions_addfchdiradd directory changing actions to a spawn file actions object

Standard C Library (libc, -lc)

#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);

The () and () 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 () is called with a relative path, it will be evaluated based on any other actions that the process has already taken. Similarly, if the () 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 () 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.

Upon successful completion, the posix_spawn_file_actions_addchdir() and posix_spawn_file_actions_addfchdir() functions return and record the corresponding file action. Otherwise, an error number will be returned.

The posix_spawn_file_actions_addchdir() and posix_spawn_file_actions_addfchdir() functions will fail if:

Insufficient memory exists to add the spawn file actions object.

Additionally, the posix_spawn_file_actions_addfchdir() function will fail if:

The file descriptor, fd, is negative or an otherwise invalid file descriptor.

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)

January 5, 2025 OmniOS