posix_spawn_file_actions_addchdir, posix_spawn_file_actions_addfchdir — add chdir or fchdir action to spawn file actions object (ADVANCED REALTIME)
[SPN] #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
*file_actions, int fildes);
The posix_spawn_file_actions_addchdir() function shall add a chdir action to the object referenced by file_actions that shall cause the working directory to be set to path (as if chdir(path) had been called) when a new process is spawned using this file actions object. A relative path shall be interpreted in relation to the working directory determined by any prior actions. The string pointed to by path shall be copied by the posix_spawn_file_actions_addchdir() function.
The posix_spawn_file_actions_addfchdir() function shall add an fchdir action to the object referenced by file_actions that shall cause the working directory to be set to fildes (as if fchdir(fildes) had been called) when a new process is spawned using this file actions object.
A spawn file actions object is as defined in posix_spawn_file_actions_addclose .
Upon successful completion, these functions shall return zero; otherwise, an error number shall be returned to indicate the error.
The posix_spawn_file_actions_addfchdir() function shall fail if:
- [EBADF]
- The value specified by fildes is negative.
These functions shall fail if:
- [ENOMEM]
- Insufficient memory exists to add to the spawn file actions object.
These functions may fail if:
- [EINVAL]
- The value specified by file_actions is invalid.
It shall not be considered an error for the path or fildes argument passed to these functions to specify a pathname or file descriptor for which the specified operation could not be performed at the time of the call. Any such error shall be detected when the associated file actions object is later used during a posix_spawn() or posix_spawnp() operation.
None.
The posix_spawn_file_actions_addchdir() and posix_spawn_file_actions_addfchdir() functions are part of the Spawn option and need not be provided on all implementations.
Changing the working directory of a child process can be useful when invoking utilities such as pax. Furthermore, the ability to add fchdir actions to posix_spawn() gives the caller as much control over relative pathnames processed in the context of the child as it would otherwise have using openat(), since all file actions are processed in sequence in the context of the child at a point where the child process is still single-threaded. Without chdir or fchdir actions, changing the working directory of the child would require a shim utility (some implementations provide
env -C /new/path program args...as an extension, but the standard does not require this extension), or else temporarily changing the working directory in the parent process prior to calling posix_spawn() (but this requires locking in a multi-threaded process, to ensure that no other thread is impacted by the temporary change to global state).
File actions are performed in a new process created by posix_spawn() or posix_spawnp() in the same order that they were added to the file actions object. Thus, the execution of an open action that was created by a call to posix_spawn_file_actions_addopen() that specifies a relative path will be affected by the execution of a chdir or fchdir action that was created by a previous call to posix_spawn_file_actions_addchdir() or posix_spawn_file_actions_addfchdir(). Likewise, a relative path passed to posix_spawn() will be affected by the last chdir or fchdir action in the file action list.
Refer to the RATIONALE section in posix_spawn_file_actions_addclose .
None.
chdir , fchdir , posix_spawn , posix_spawn_file_actions_addclose , posix_spawn_file_actions_destroy
XBD <spawn.h>
First released in Issue 8. Derived from Solaris posix_spawn_file_actions_addchdir_np.
return to top of page