Starting processes v0.1.0

Source
posix_spawn and its file actions, and waiting for and signalling a child.

SpawnFileActions

pub struct SpawnFileActions {
    // private fields
}

Room for a posix_spawn_file_actions_t, which each C library sizes its own way and none larger than this. Only ever passed by address to the posix_spawn_file_actions_* calls, which initialize and read it.

Source

Constructors

SpawnFileActions

pub func SpawnFileActions() -> SpawnFileActions

Zeroed storage for posix_spawn_file_actions_init to initialize.

Returns: the storage

Source

F_SETFD

pub const F_SETFD: int32 = 2;

F_SETFD: the fcntl command that sets a descriptor's flags.

Source

FD_CLOEXEC

pub const FD_CLOEXEC: int32 = 1;

FD_CLOEXEC: close the descriptor when the process starts another program.

Source

WNOHANG

pub const WNOHANG: int32 = 1;

WNOHANG: have waitpid return at once when the child has not finished.

Source

SIGKILL

pub const SIGKILL: int32 = 9;

SIGKILL: the signal that ends a process at once and cannot be caught.

Source

posix_spawnp

pub extern func posix_spawnp(
    pid: *var int32,
    file: *char8,
    fileActions: *SpawnFileActions,
    attributes: *opaque,
    arguments: **char8,
    environment: **char8
) -> int32

Starts file, found through PATH when it has no slash, as a child process.

See also: https://man7.org/linux/man-pages/man3/posix_spawn.3.html

Source

Parameters

NameTypeDescription
pid*var int32receives the child's process identifier
file*char8the program, NUL-terminated
fileActions*SpawnFileActionsthe descriptor and directory setup to run in the child first, or null
attributes*opaquespawn attributes, or null for the defaults
arguments**char8the argument vector, its first entry the program's name, ended by null
environment**char8the environment, NAME=VALUE entries ended by null

Returns: zero, or an error number

posix_spawn_file_actions_init

pub extern func posix_spawn_file_actions_init(actions: *var SpawnFileActions) -> int32

Initializes an empty list of file actions.

See also: https://man7.org/linux/man-pages/man3/posix_spawn_file_actions_init.3.html

Source

Parameters

NameTypeDescription
actions*var SpawnFileActionsthe storage to initialize

Returns: zero, or an error number

posix_spawn_file_actions_destroy

pub extern func posix_spawn_file_actions_destroy(actions: *var SpawnFileActions) -> int32

Releases what posix_spawn_file_actions_init and the actions added since set up.

See also: https://man7.org/linux/man-pages/man3/posix_spawn_file_actions_destroy.3.html

Source

Parameters

NameTypeDescription
actions*var SpawnFileActionsinitialized file actions

Returns: zero, or an error number

posix_spawn_file_actions_adddup2

pub extern func posix_spawn_file_actions_adddup2(
    actions: *var SpawnFileActions,
    fd: int32,
    newFd: int32
) -> int32

Adds an action duplicating fd onto newFd in the child.

See also: https://man7.org/linux/man-pages/man3/posix_spawn_file_actions_adddup2.3.html

Source

Parameters

NameTypeDescription
actions*var SpawnFileActionsinitialized file actions
fdint32the descriptor to duplicate
newFdint32the descriptor it becomes

Returns: zero, or an error number

posix_spawn_file_actions_addopen

pub extern func posix_spawn_file_actions_addopen(
    actions: *var SpawnFileActions,
    fd: int32,
    path: *char8,
    flags: int32,
    mode: FileMode
) -> int32

Adds an action opening path as fd in the child.

See also: https://man7.org/linux/man-pages/man3/posix_spawn_file_actions_addopen.3.html

Source

Parameters

NameTypeDescription
actions*var SpawnFileActionsinitialized file actions
fdint32the descriptor the file becomes
path*char8the file, NUL-terminated
flagsint32the open flags
modeFileModethe permissions of a file the open creates

Returns: zero, or an error number

posix_spawn_file_actions_addchdir_np

pub extern func posix_spawn_file_actions_addchdir_np(
    actions: *var SpawnFileActions,
    path: *char8
) -> int32

Adds an action changing the child's working directory to path.

See also: https://man7.org/linux/man-pages/man3/posix_spawn_file_actions_addchdir_np.3.html

Source

Parameters

NameTypeDescription
actions*var SpawnFileActionsinitialized file actions
path*char8the directory, NUL-terminated

Returns: zero, or an error number

waitpid

pub extern func waitpid(
    pid: int32,
    status: *var int32,
    options: int32
) -> int32

Waits for a child to change state, and reports how it finished.

See also: https://man7.org/linux/man-pages/man2/waitpid.2.html

Source

Parameters

NameTypeDescription
pidint32the child's process identifier
status*var int32receives the encoded status
optionsint32zero to wait, or WNOHANG to return at once when the child is still running

Returns: the child's identifier, zero with WNOHANG when it is still running, or -1 with the reason in errno

kill

pub extern func kill(pid: int32, signal: int32) -> int32

Sends a signal to a process.

See also: https://man7.org/linux/man-pages/man2/kill.2.html

Source

Parameters

NameTypeDescription
pidint32the process
signalint32the signal number, such as SIGKILL

Returns: zero, or -1 with the reason in errno

fcntl

pub extern func fcntl(
    fd: int32,
    command: int32,
    ...
) -> int32

Performs a control operation on a descriptor, such as setting its flags with F_SETFD.

See also: https://man7.org/linux/man-pages/man2/fcntl.2.html

Source

Parameters

NameTypeDescription
fdint32the descriptor
commandint32the operation
...

Returns: the operation's result, or -1 with the reason in errno

__errno_location

pub extern func __errno_location() -> *var int32

Returns the address of the calling thread's errno, where the C library calls above leave their reason.

See also: https://man7.org/linux/man-pages/man3/errno.3.html

Source

Returns: the errno's address