123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752 |
- /*++
- Copyright (c) 2016 Minoca Corp.
- This file is licensed under the terms of the GNU Lesser General Public
- License version 3. Alternative licensing terms are available. Contact
- info@minocacorp.com for details.
- Module Name:
- spawn.h
- Abstract:
- This header contains definitions for the posix_spawn
- Author:
- Evan Green 20-Jul-2016
- --*/
- #ifndef _SPAWN_H
- #define _SPAWN_H
- //
- // ------------------------------------------------------------------- Includes
- //
- #include <libcbase.h>
- #include <sched.h>
- #include <signal.h>
- #include <sys/types.h>
- //
- // ---------------------------------------------------------------- Definitions
- //
- #ifdef __cplusplus
- extern "C" {
- #endif
- //
- // Set this flag to have the child's effective user and group IDs set back to
- // its real IDs.
- //
- #define POSIX_SPAWN_RESETIDS 0x00000001
- //
- // Set this flag to have the child's process group ID set as defined in the
- // attributes. If no attribute was set and this flag is set, the process group
- // ID will be set to the process ID of the new child.
- //
- #define POSIX_SPAWN_SETPGROUP 0x00000002
- //
- // Set this flag to set the scheduling parameter of the child process.
- //
- #define POSIX_SPAWN_SETSCHEDPARAM 0x00000004
- //
- // Set this flag to set the scheduling policy of the child process.
- //
- #define POSIX_SPAWN_SETSCHEDULER 0x00000008
- //
- // Set this flag to reset the signals defined in the setsigdefault attribute
- // back to their default disposition.
- //
- #define POSIX_SPAWN_SETSIGDEF 0x00000010
- //
- // Set this flag to set the signal mask specified in the setsigmask attribute
- // in the child process.
- //
- #define POSIX_SPAWN_SETSIGMASK 0x00000020
- //
- // ------------------------------------------------------ Data Type Definitions
- //
- //
- // Define the opaque attribute types. Users should use the init/destroy and
- // get/set methods defined below in this file to manipulate these types.
- //
- typedef struct __posix_spawnattr_t *posix_spawnattr_t;
- typedef struct __posix_spawn_file_actions_t *posix_spawn_file_actions_t;
- //
- // -------------------------------------------------------------------- Globals
- //
- //
- // -------------------------------------------------------- Function Prototypes
- //
- LIBC_API
- int
- posix_spawn (
- pid_t *ChildPid,
- const char *Path,
- const posix_spawn_file_actions_t *FileActions,
- const posix_spawnattr_t *Attributes,
- char *const Arguments[],
- char *const Environment[]
- );
- /*++
- Routine Description:
- This routine spawns a new child process.
- Arguments:
- ChildPid - Supplies an optional pointer where the child process ID will be
- returned on success.
- Path - Supplies a pointer to the file path to execute.
- FileActions - Supplies an optional pointer to the file actions to execute
- in the child.
- Attributes - Supplies an optional pointer to the spawn attributes that
- affect various properties of the child.
- Arguments - Supplies the arguments to pass to the new child.
- Environment - Supplies an optional pointer to the environment to pass
- to the new child.
- Return Value:
- 0 on success.
- Returns an error number on failure.
- --*/
- LIBC_API
- int
- posix_spawnp (
- pid_t *ChildPid,
- const char *File,
- const posix_spawn_file_actions_t *FileActions,
- const posix_spawnattr_t *Attributes,
- char *const Arguments[],
- char *const Environment[]
- );
- /*++
- Routine Description:
- This routine spawns a new child process. It is identical to posix_spawn
- except the path is searched to find the file argument.
- Arguments:
- ChildPid - Supplies an optional pointer where the child process ID will be
- returned on success.
- File - Supplies a pointer to the file to execute. If this path contains a
- slash, it will be used as a relative path from the current directory
- or an absolute path. If this path does not contain a slash, it will
- use the PATH environment variable from the new child environment
- to attempt to find the path.
- FileActions - Supplies an optional pointer to the file actions to execute
- in the child.
- Attributes - Supplies an optional pointer to the spawn attributes that
- affect various properties of the child.
- Arguments - Supplies the arguments to pass to the new child.
- Environment - Supplies an optional pointer to the environment to pass
- to the new child.
- Return Value:
- 0 on success.
- Returns an error number on failure.
- --*/
- //
- // File action functions
- //
- LIBC_API
- int
- posix_spawn_file_actions_init (
- posix_spawn_file_actions_t *FileActions
- );
- /*++
- Routine Description:
- This routine initializes a set of posix spawn file action.
- Arguments:
- FileActions - Supplies a pointer to the file actions to initialize.
- Return Value:
- 0 on success. The caller must call the corresponding destroy routine to
- avoid leaking resources.
- Returns an error number on failure. The caller should not call destroy on
- this object.
- --*/
- LIBC_API
- int
- posix_spawn_file_actions_destroy (
- posix_spawn_file_actions_t *FileActions
- );
- /*++
- Routine Description:
- This routine destroys a set of posix spawn file actions.
- Arguments:
- FileActions - Supplies a pointer to the file actions to destroy.
- Return Value:
- 0 always.
- --*/
- LIBC_API
- int
- posix_spawn_file_actions_addopen (
- posix_spawn_file_actions_t *FileActions,
- int FileDescriptor,
- const char *Path,
- int OpenFlags,
- mode_t CreatePermissions
- );
- /*++
- Routine Description:
- This routine adds an open call to the set of file attributes. The spawn
- function will attempt to open the given file in the child.
- Arguments:
- FileActions - Supplies a pointer to the initialized file actions.
- FileDescriptor - Supplies the descriptor number to set the open file to.
- Path - Supplies a pointer to the path to open.
- OpenFlags - Supplies the set of open flags to use when opening the file.
- See O_* flags or the definition of the open function for details.
- CreatePermissions - Supplies the permissions to set on the new file if it
- is creates. See S_I* definitions or the definition of the open function
- for details.
- Return Value:
- 0 on success.
- Returns an error number on failure.
- --*/
- LIBC_API
- int
- posix_spawn_file_actions_adddup2 (
- posix_spawn_file_actions_t *FileActions,
- int FileDescriptor,
- int DestinationDescriptor
- );
- /*++
- Routine Description:
- This routine adds a dup2 call to the set of file attributes. The spawn
- function will attempt to duplicate the given descriptor in the child.
- Arguments:
- FileActions - Supplies a pointer to the initialized file actions.
- FileDescriptor - Supplies the descriptor to copy.
- DestinationDescriptor - Supplies the descriptor number to copy the
- descriptor to.
- Return Value:
- 0 on success.
- Returns an error number on failure.
- --*/
- LIBC_API
- int
- posix_spawn_file_actions_addclose (
- posix_spawn_file_actions_t *FileActions,
- int FileDescriptor
- );
- /*++
- Routine Description:
- This routine adds a close call to the set of file attributes. The spawn
- function will attempt to close the given descriptor in the child.
- Arguments:
- FileActions - Supplies a pointer to the initialized file actions.
- FileDescriptor - Supplies the descriptor to close.
- Return Value:
- 0 on success.
- Returns an error number on failure.
- --*/
- //
- // Spawn attribute functions
- //
- LIBC_API
- int
- posix_spawnattr_init (
- posix_spawnattr_t *Attributes
- );
- /*++
- Routine Description:
- This routine initializes a set of spawn attributes.
- Arguments:
- Attributes - Supplies a pointer to the attributes to initialize.
- Return Value:
- 0 on success. The caller must call the corresponding destroy routine to
- avoid leaking resources.
- Returns an error number on failure. The caller should not call destroy in
- this case.
- --*/
- LIBC_API
- int
- posix_spawnattr_destroy (
- posix_spawnattr_t *Attributes
- );
- /*++
- Routine Description:
- This routine destroys a set of spawn attributes.
- Arguments:
- Attributes - Supplies a pointer to the attributes to destroy.
- Return Value:
- 0 always.
- --*/
- //
- // Spawn attribute get functions
- //
- LIBC_API
- int
- posix_spawnattr_getflags (
- const posix_spawnattr_t *Attributes,
- short *Flags
- );
- /*++
- Routine Description:
- This routine returns the current flags on a set of spawn attributes.
- Arguments:
- Attributes - Supplies a pointer to the initialized attributes.
- Flags - Supplies a pointer where the flags will be returned on success.
- Return Value:
- 0 on success (always).
- Returns an error number on failure.
- --*/
- LIBC_API
- int
- posix_spawnattr_getpgroup (
- const posix_spawnattr_t *Attributes,
- pid_t *ProcessGroup
- );
- /*++
- Routine Description:
- This routine returns the current process group on a set of spawn attributes.
- Arguments:
- Attributes - Supplies a pointer to the initialized attributes.
- ProcessGroup - Supplies a pointer where the process group will be returned
- on success.
- Return Value:
- 0 on success (always).
- Returns an error number on failure.
- --*/
- LIBC_API
- int
- posix_spawnattr_getschedparam (
- const posix_spawnattr_t *Attributes,
- struct sched_param *Parameters
- );
- /*++
- Routine Description:
- This routine returns the current scheduling parameters on a set of spawn
- attributes.
- Arguments:
- Attributes - Supplies a pointer to the initialized attributes.
- Parameters - Supplies a pointer where the scheduling parameters will be
- returned on success.
- Return Value:
- 0 on success (always).
- Returns an error number on failure.
- --*/
- LIBC_API
- int
- posix_spawnattr_getschedpolicy (
- const posix_spawnattr_t *Attributes,
- int *Policy
- );
- /*++
- Routine Description:
- This routine returns the current scheduling policy on a set of spawn
- attributes.
- Arguments:
- Attributes - Supplies a pointer to the initialized attributes.
- Policy - Supplies a pointer where the scheduling policy will be returned on
- success.
- Return Value:
- 0 on success (always).
- Returns an error number on failure.
- --*/
- LIBC_API
- int
- posix_spawnattr_getsigdefault (
- const posix_spawnattr_t *Attributes,
- sigset_t *DefaultSignals
- );
- /*++
- Routine Description:
- This routine returns the current default signal set on a set of spawn
- attributes.
- Arguments:
- Attributes - Supplies a pointer to the initialized attributes.
- DefaultSignals - Supplies a pointer where the set of signals to be returned
- to their default dispositions will be returned on success.
- Return Value:
- 0 on success (always).
- Returns an error number on failure.
- --*/
- LIBC_API
- int
- posix_spawnattr_getsigmask (
- const posix_spawnattr_t *Attributes,
- sigset_t *Mask
- );
- /*++
- Routine Description:
- This routine returns the current signal mask on a set of spawn attributes.
- Arguments:
- Attributes - Supplies a pointer to the initialized attributes.
- Mask - Supplies a pointer where the signal mask to be set on the child
- process will be returned on success.
- Return Value:
- 0 on success (always).
- Returns an error number on failure.
- --*/
- //
- // Spawn attribute set functions
- //
- LIBC_API
- int
- posix_spawnattr_setflags (
- posix_spawnattr_t *Attributes,
- short Flags
- );
- /*++
- Routine Description:
- This routine sets the current flags on a set of spawn attributes.
- Arguments:
- Attributes - Supplies a pointer to the initialized attributes.
- Flags - Supplies the new flags to set.
- Return Value:
- 0 on success (always).
- Returns an error number on failure.
- --*/
- LIBC_API
- int
- posix_spawnattr_setpgroup (
- posix_spawnattr_t *Attributes,
- pid_t ProcessGroup
- );
- /*++
- Routine Description:
- This routine sets the current process group on a set of spawn attributes.
- Arguments:
- Attributes - Supplies a pointer to the initialized attributes.
- ProcessGroup - Supplies the process group to set the child to.
- Return Value:
- 0 on success (always).
- Returns an error number on failure.
- --*/
- LIBC_API
- int
- posix_spawnattr_setschedparam (
- posix_spawnattr_t *Attributes,
- const struct sched_param *Parameters
- );
- /*++
- Routine Description:
- This routine sets the current scheduling parameters on a set of spawn
- attributes.
- Arguments:
- Attributes - Supplies a pointer to the initialized attributes.
- Parameters - Supplies a pointer to the scheduling parameters to set in the
- child.
- Return Value:
- 0 on success (always).
- Returns an error number on failure.
- --*/
- LIBC_API
- int
- posix_spawnattr_setschedpolicy (
- posix_spawnattr_t *Attributes,
- int Policy
- );
- /*++
- Routine Description:
- This routine sets the current scheduling policy on a set of spawn
- attributes.
- Arguments:
- Attributes - Supplies a pointer to the initialized attributes.
- Policy - Supplies the scheduling policy to set in the child.
- Return Value:
- 0 on success (always).
- Returns an error number on failure.
- --*/
- LIBC_API
- int
- posix_spawnattr_setsigdefault (
- posix_spawnattr_t *Attributes,
- const sigset_t *DefaultSignals
- );
- /*++
- Routine Description:
- This routine sets the current default signal set on a set of spawn
- attributes.
- Arguments:
- Attributes - Supplies a pointer to the initialized attributes.
- DefaultSignals - Supplies a pointer to the set of signals to return to
- their default dispositions in the child.
- Return Value:
- 0 on success (always).
- Returns an error number on failure.
- --*/
- LIBC_API
- int
- posix_spawnattr_setsigmask (
- posix_spawnattr_t *Attributes,
- const sigset_t *Mask
- );
- /*++
- Routine Description:
- This routine sets the current signal mask on a set of spawn attributes.
- Arguments:
- Attributes - Supplies a pointer to the initialized attributes.
- Mask - Supplies a pointer to the signal mask to set in the child.
- Return Value:
- 0 on success (always).
- Returns an error number on failure.
- --*/
- #ifdef __cplusplus
- }
- #endif
- #endif
|