xref: /freebsd/lib/libc/gen/posix_spawn.3 (revision 6e1fc0118033f42b7c0d3623c8f67a89ebecabb2)
162187b41SDavid Xu.\" Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org>
262187b41SDavid Xu.\" All rights reserved.
362187b41SDavid Xu.\"
462187b41SDavid Xu.\" Redistribution and use in source and binary forms, with or without
562187b41SDavid Xu.\" modification, are permitted provided that the following conditions
662187b41SDavid Xu.\" are met:
762187b41SDavid Xu.\" 1. Redistributions of source code must retain the above copyright
862187b41SDavid Xu.\"    notice, this list of conditions and the following disclaimer.
962187b41SDavid Xu.\" 2. Redistributions in binary form must reproduce the above copyright
1062187b41SDavid Xu.\"    notice, this list of conditions and the following disclaimer in the
1162187b41SDavid Xu.\"    documentation and/or other materials provided with the distribution.
1262187b41SDavid Xu.\"
1362187b41SDavid Xu.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1462187b41SDavid Xu.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1562187b41SDavid Xu.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1662187b41SDavid Xu.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1762187b41SDavid Xu.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1862187b41SDavid Xu.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1962187b41SDavid Xu.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2062187b41SDavid Xu.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2162187b41SDavid Xu.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2262187b41SDavid Xu.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2362187b41SDavid Xu.\" SUCH DAMAGE.
2462187b41SDavid Xu.\"
2562187b41SDavid Xu.\" Portions of this text are reprinted and reproduced in electronic form
2662187b41SDavid Xu.\" from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology --
2762187b41SDavid Xu.\" Portable Operating System Interface (POSIX), The Open Group Base
2862187b41SDavid Xu.\" Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of
2962187b41SDavid Xu.\" Electrical and Electronics Engineers, Inc and The Open Group.  In the
3062187b41SDavid Xu.\" event of any discrepancy between this version and the original IEEE and
3162187b41SDavid Xu.\" The Open Group Standard, the original IEEE and The Open Group Standard is
3262187b41SDavid Xu.\" the referee document.  The original Standard can be obtained online at
3362187b41SDavid Xu.\"	http://www.opengroup.org/unix/online.html.
3462187b41SDavid Xu.\"
35a725a7a2SKonstantin Belousov.Dd March 4, 2024
3662187b41SDavid Xu.Dt POSIX_SPAWN 3
3762187b41SDavid Xu.Os
3862187b41SDavid Xu.Sh NAME
3962187b41SDavid Xu.Nm posix_spawn ,
4062187b41SDavid Xu.Nm posix_spawnp
4162187b41SDavid Xu.Nd "spawn a process"
4262187b41SDavid Xu.Sh LIBRARY
4362187b41SDavid Xu.Lb libc
4462187b41SDavid Xu.Sh SYNOPSIS
4562187b41SDavid Xu.In spawn.h
4662187b41SDavid Xu.Ft int
478ed1e4a5SKonstantin Belousov.Fo posix_spawn
488ed1e4a5SKonstantin Belousov.Fa "pid_t *restrict pid"
498ed1e4a5SKonstantin Belousov.Fa "const char *restrict path"
508ed1e4a5SKonstantin Belousov.Fa "const posix_spawn_file_actions_t *file_actions"
518ed1e4a5SKonstantin Belousov.Fa "const posix_spawnattr_t *restrict attrp"
528ed1e4a5SKonstantin Belousov.Fa "char *const argv[restrict]"
538ed1e4a5SKonstantin Belousov.Fa "char *const envp[restrict]"
548ed1e4a5SKonstantin Belousov.Fc
5562187b41SDavid Xu.Ft int
568ed1e4a5SKonstantin Belousov.Fo posix_spawnp
578ed1e4a5SKonstantin Belousov.Fa "pid_t *restrict pid"
588ed1e4a5SKonstantin Belousov.Fa "const char *restrict file"
598ed1e4a5SKonstantin Belousov.Fa "const posix_spawn_file_actions_t *file_actions"
608ed1e4a5SKonstantin Belousov.Fa "const posix_spawnattr_t *restrict attrp"
618ed1e4a5SKonstantin Belousov.Fa "char *const argv[restrict]"
628ed1e4a5SKonstantin Belousov.Fa "char *const envp[restrict]"
638ed1e4a5SKonstantin Belousov.Fc
6462187b41SDavid Xu.Sh DESCRIPTION
6562187b41SDavid XuThe
6662187b41SDavid Xu.Fn posix_spawn
6762187b41SDavid Xuand
6862187b41SDavid Xu.Fn posix_spawnp
6962187b41SDavid Xufunctions create a new process (child process) from the specified
7062187b41SDavid Xuprocess image.
7162187b41SDavid XuThe new process image is constructed from a regular executable
7262187b41SDavid Xufile called the new process image file.
7362187b41SDavid Xu.Pp
7462187b41SDavid XuWhen a C program is executed as the result of this call, it is
7562187b41SDavid Xuentered as a C-language function call as follows:
7662187b41SDavid Xu.Bd -literal -offset indent
7762187b41SDavid Xuint main(int argc, char *argv[]);
7862187b41SDavid Xu.Ed
7962187b41SDavid Xu.Pp
8062187b41SDavid Xuwhere
8162187b41SDavid Xu.Fa argc
8262187b41SDavid Xuis the argument count and
8362187b41SDavid Xu.Fa argv
8462187b41SDavid Xuis an array of character pointers to the arguments themselves.
8562187b41SDavid XuIn addition, the variable:
8662187b41SDavid Xu.Bd -literal -offset indent
8762187b41SDavid Xuextern char **environ;
8862187b41SDavid Xu.Ed
8962187b41SDavid Xu.Pp
9062187b41SDavid Xupoints to an array of character pointers to
9162187b41SDavid Xuthe environment strings.
9262187b41SDavid Xu.Pp
9362187b41SDavid XuThe argument
9462187b41SDavid Xu.Fa argv
9562187b41SDavid Xuis an array of character pointers to null-terminated
9662187b41SDavid Xustrings.
9762187b41SDavid XuThe last member of this array is a null pointer and is not counted
9862187b41SDavid Xuin
9962187b41SDavid Xu.Fa argc .
10062187b41SDavid XuThese strings constitute the argument list available to the new process
10162187b41SDavid Xuimage.
10262187b41SDavid XuThe value in
10362187b41SDavid Xu.Fa argv Ns [0]
10462187b41SDavid Xushould point to
10562187b41SDavid Xua filename that is associated with the process image being started by
10662187b41SDavid Xuthe
10762187b41SDavid Xu.Fn posix_spawn
10862187b41SDavid Xuor
10962187b41SDavid Xu.Fn posix_spawnp
11062187b41SDavid Xufunction.
11162187b41SDavid Xu.Pp
11262187b41SDavid XuThe argument
11362187b41SDavid Xu.Fa envp
11462187b41SDavid Xuis an array of character pointers to null-terminated strings.
11562187b41SDavid XuThese strings constitute the environment for the new process image.
11662187b41SDavid XuThe environment array is terminated by a null pointer.
11762187b41SDavid Xu.Pp
11862187b41SDavid XuThe
11962187b41SDavid Xu.Fa path
12062187b41SDavid Xuargument to
12162187b41SDavid Xu.Fn posix_spawn
12262187b41SDavid Xuis a pathname that identifies the new process image file to execute.
12362187b41SDavid Xu.Pp
12462187b41SDavid XuThe
12562187b41SDavid Xu.Fa file
12662187b41SDavid Xuparameter to
12762187b41SDavid Xu.Fn posix_spawnp
12862187b41SDavid Xuis used to construct a pathname that identifies the new process
12962187b41SDavid Xuimage file.
13062187b41SDavid XuIf the file parameter contains a slash character, the file parameter
13162187b41SDavid Xuis used as the pathname for the new process image file.
13262187b41SDavid XuOtherwise, the path prefix for this file is obtained by a search
13362187b41SDavid Xuof the directories passed as the environment variable
13462187b41SDavid Xu.Dq Ev PATH .
13562187b41SDavid XuIf this variable is not specified,
13662187b41SDavid Xuthe default path is set according to the
13762187b41SDavid Xu.Dv _PATH_DEFPATH
13862187b41SDavid Xudefinition in
13962187b41SDavid Xu.In paths.h ,
14062187b41SDavid Xuwhich is set to
14143d53dbaSJilles Tjoelker.Dq Ev /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin .
14262187b41SDavid Xu.Pp
14362187b41SDavid XuIf
14462187b41SDavid Xu.Fa file_actions
14562187b41SDavid Xuis a null pointer, then file descriptors open in the
14662187b41SDavid Xucalling process remain open in the child process, except for those
14762187b41SDavid Xuwhose close-on-exec flag
14862187b41SDavid Xu.Dv FD_CLOEXEC
14962187b41SDavid Xuis set (see
15062187b41SDavid Xu.Fn fcntl ) .
15162187b41SDavid XuFor those
15262187b41SDavid Xufile descriptors that remain open, all attributes of the corresponding
15362187b41SDavid Xuopen file descriptions, including file locks (see
15462187b41SDavid Xu.Fn fcntl ) ,
15562187b41SDavid Xuremain unchanged.
15662187b41SDavid Xu.Pp
15762187b41SDavid XuIf
15862187b41SDavid Xu.Fa file_actions
15962187b41SDavid Xuis not NULL, then the file descriptors open in the child process are
16062187b41SDavid Xuthose open in the calling process as modified by the spawn file
16162187b41SDavid Xuactions object pointed to by
16262187b41SDavid Xu.Fa file_actions
16362187b41SDavid Xuand the
16462187b41SDavid Xu.Dv FD_CLOEXEC
16562187b41SDavid Xuflag of each remaining open file descriptor after the spawn file actions
16662187b41SDavid Xuhave been processed.
16762187b41SDavid XuThe effective order of processing the spawn file actions are:
16862187b41SDavid Xu.Bl -enum
16962187b41SDavid Xu.It
17062187b41SDavid XuThe set of open file descriptors for the child process initially
17162187b41SDavid Xuare the same set as is open for the calling process.
17262187b41SDavid XuAll attributes of the corresponding open file descriptions, including
17362187b41SDavid Xufile locks (see
17462187b41SDavid Xu.Fn fcntl ) ,
17562187b41SDavid Xuremain unchanged.
17662187b41SDavid Xu.It
17762187b41SDavid XuThe signal mask, signal default actions, and the effective user and
17862187b41SDavid Xugroup IDs for the child process are changed as specified in the
17962187b41SDavid Xuattributes object referenced by
18062187b41SDavid Xu.Fa attrp .
18162187b41SDavid Xu.It
18262187b41SDavid XuThe file actions specified by the spawn file actions object are
18362187b41SDavid Xuperformed in the order in which they were added to the spawn file
18462187b41SDavid Xuactions object.
18562187b41SDavid Xu.It
18662187b41SDavid XuAny file descriptor that has its
18762187b41SDavid Xu.Dv FD_CLOEXEC
18862187b41SDavid Xuflag set (see
18962187b41SDavid Xu.Fn fcntl )
19062187b41SDavid Xuis closed.
19162187b41SDavid Xu.El
19262187b41SDavid Xu.Pp
19362187b41SDavid XuThe
19462187b41SDavid Xu.Vt posix_spawnattr_t
19562187b41SDavid Xuspawn attributes object type is defined in
19662187b41SDavid Xu.In spawn.h .
19762187b41SDavid XuIt contains the attributes defined below.
19862187b41SDavid Xu.Pp
19962187b41SDavid XuIf the
20062187b41SDavid Xu.Dv POSIX_SPAWN_SETPGROUP
20162187b41SDavid Xuflag is set in the spawn-flags attribute of the object referenced by
20262187b41SDavid Xu.Fa attrp ,
20362187b41SDavid Xuand the spawn-pgroup attribute of the same object is non-zero, then the
20462187b41SDavid Xuchild's process group is as specified in the spawn-pgroup
20562187b41SDavid Xuattribute of the object referenced by
20662187b41SDavid Xu.Fa attrp .
20762187b41SDavid Xu.Pp
20862187b41SDavid XuAs a special case, if the
20962187b41SDavid Xu.Dv POSIX_SPAWN_SETPGROUP
21062187b41SDavid Xuflag is set in the spawn-flags attribute of the object referenced by
21162187b41SDavid Xu.Fa attrp ,
21262187b41SDavid Xuand the spawn-pgroup attribute of the same object is set to zero, then
21362187b41SDavid Xuthe child is in a new process group with a process group ID equal
21462187b41SDavid Xuto its process ID.
21562187b41SDavid Xu.Pp
21662187b41SDavid XuIf the
21762187b41SDavid Xu.Dv POSIX_SPAWN_SETPGROUP
21862187b41SDavid Xuflag is not set in the spawn-flags attribute of the object referenced by
21962187b41SDavid Xu.Fa attrp ,
22062187b41SDavid Xuthe new child process inherits the parent's process group.
22162187b41SDavid Xu.Pp
22262187b41SDavid XuIf the
22362187b41SDavid Xu.Dv POSIX_SPAWN_SETSCHEDPARAM
22462187b41SDavid Xuflag is set in the spawn-flags attribute of the object referenced by
22562187b41SDavid Xu.Fa attrp ,
22662187b41SDavid Xubut
22762187b41SDavid Xu.Dv POSIX_SPAWN_SETSCHEDULER
22862187b41SDavid Xuis not set, the new process image initially has the scheduling
22962187b41SDavid Xupolicy of the calling process with the scheduling parameters specified
23062187b41SDavid Xuin the spawn-schedparam attribute of the object referenced by
23162187b41SDavid Xu.Fa attrp .
23262187b41SDavid Xu.Pp
23362187b41SDavid XuIf the
23462187b41SDavid Xu.Dv POSIX_SPAWN_SETSCHEDULER
23562187b41SDavid Xuflag is set in the spawn-flags attribute of the object referenced by
23662187b41SDavid Xu.Fa attrp
23762187b41SDavid Xu(regardless of the setting of the
23862187b41SDavid Xu.Dv POSIX_SPAWN_SETSCHEDPARAM
23962187b41SDavid Xuflag), the new process image initially has the scheduling policy
24062187b41SDavid Xuspecified in the spawn-schedpolicy attribute of the object referenced by
24162187b41SDavid Xu.Fa attrp
24262187b41SDavid Xuand the scheduling parameters specified in the spawn-schedparam
24362187b41SDavid Xuattribute of the same object.
24462187b41SDavid Xu.Pp
24562187b41SDavid XuThe
24662187b41SDavid Xu.Dv POSIX_SPAWN_RESETIDS
24762187b41SDavid Xuflag in the spawn-flags attribute of the object referenced by
24862187b41SDavid Xu.Fa attrp
24962187b41SDavid Xugoverns the effective user ID of the child process.
25062187b41SDavid XuIf this flag is not set, the child process inherits the parent
25162187b41SDavid Xuprocess' effective user ID.
25262187b41SDavid XuIf this flag is set, the child process' effective user ID is reset
25362187b41SDavid Xuto the parent's real user ID.
25462187b41SDavid XuIn either case, if the set-user-ID mode bit of the new process image
25562187b41SDavid Xufile is set, the effective user ID of the child process becomes
25662187b41SDavid Xuthat file's owner ID before the new process image begins execution.
25762187b41SDavid Xu.Pp
25862187b41SDavid XuThe
25962187b41SDavid Xu.Dv POSIX_SPAWN_RESETIDS
26062187b41SDavid Xuflag in the spawn-flags attribute of the object referenced by
26162187b41SDavid Xu.Fa attrp
26262187b41SDavid Xualso governs the effective group ID of the child process.
26362187b41SDavid XuIf this flag is not set, the child process inherits the parent
26462187b41SDavid Xuprocess' effective group ID.
26562187b41SDavid XuIf this flag is set, the child process' effective group ID is
26662187b41SDavid Xureset to the parent's real group ID.
26762187b41SDavid XuIn either case, if the set-group-ID mode bit of the new process image
26862187b41SDavid Xufile is set, the effective group ID of the child process becomes
26962187b41SDavid Xuthat file's group ID before the new process image begins execution.
27062187b41SDavid Xu.Pp
27162187b41SDavid XuIf the
27262187b41SDavid Xu.Dv POSIX_SPAWN_SETSIGMASK
27362187b41SDavid Xuflag is set in the spawn-flags attribute of the object referenced by
27462187b41SDavid Xu.Fa attrp ,
27562187b41SDavid Xuthe child process initially has the signal mask specified in the
27662187b41SDavid Xuspawn-sigmask attribute of the object referenced by
27762187b41SDavid Xu.Fa attrp .
27862187b41SDavid Xu.Pp
27962187b41SDavid XuIf the
28062187b41SDavid Xu.Dv POSIX_SPAWN_SETSIGDEF
28162187b41SDavid Xuflag is set in the spawn-flags attribute of the object referenced by
28262187b41SDavid Xu.Fa attrp ,
28362187b41SDavid Xuthe signals specified in the spawn-sigdefault attribute of the same
2848d55975fSBryan Dreweryobject are set to their default actions in the child process.
2858d55975fSBryan DrewerySignals set to the default action in the parent process are set to
28662187b41SDavid Xuthe default action in the child process.
28762187b41SDavid Xu.Pp
2888d55975fSBryan DrewerySignals set to be caught by the calling process are set to the
28962187b41SDavid Xudefault action in the child process.
29062187b41SDavid Xu.Pp
2918d55975fSBryan DrewerySignals set to be ignored by the calling process image are set to
29262187b41SDavid Xube ignored by the child process, unless otherwise specified by the
29362187b41SDavid Xu.Dv POSIX_SPAWN_SETSIGDEF
29462187b41SDavid Xuflag being set in the spawn-flags attribute of the object referenced by
29562187b41SDavid Xu.Fa attrp
29662187b41SDavid Xuand the signals being indicated in the spawn-sigdefault attribute
29762187b41SDavid Xuof the object referenced by
29862187b41SDavid Xu.Fa attrp .
29962187b41SDavid Xu.Pp
300a725a7a2SKonstantin BelousovThe Address Space Layout Randomization for the newly spawned process
301a725a7a2SKonstantin Belousovcan be disabled by specifying the
302a725a7a2SKonstantin Belousov.Dv POSIX_SPAWN_DISABLE_ASLR_NP
303a725a7a2SKonstantin Belousovflag in the spawn-flags attribute.
304a725a7a2SKonstantin BelousovThis setting is inherited by future children of the child as well.
305a725a7a2SKonstantin BelousovSee
306a725a7a2SKonstantin Belousov.Xr procctl 2
307a725a7a2SKonstantin Belousovfor more details.
308a725a7a2SKonstantin Belousov.Pp
30962187b41SDavid XuIf the value of the
31062187b41SDavid Xu.Fa attrp
31162187b41SDavid Xupointer is NULL, then the default values are used.
31262187b41SDavid Xu.Pp
31362187b41SDavid XuAll process attributes, other than those influenced by the attributes
31462187b41SDavid Xuset in the object referenced by
31562187b41SDavid Xu.Fa attrp
31662187b41SDavid Xuas specified above or by the file descriptor manipulations specified in
31762187b41SDavid Xu.Fa file_actions ,
31862187b41SDavid Xuappear in the new process image as though
31962187b41SDavid Xu.Fn vfork
32062187b41SDavid Xuhad been called to create a child process and then
32162187b41SDavid Xu.Fn execve
32262187b41SDavid Xuhad been called by the child process to execute the new process image.
32362187b41SDavid Xu.Pp
3242c96ea9cSEnji CooperThe implementation uses
3252c96ea9cSEnji Cooper.Fn vfork ,
3262c96ea9cSEnji Cooperthus the fork handlers are not run when
32762187b41SDavid Xu.Fn posix_spawn
32862187b41SDavid Xuor
32962187b41SDavid Xu.Fn posix_spawnp
33062187b41SDavid Xuis called.
33162187b41SDavid Xu.Sh RETURN VALUES
33262187b41SDavid XuUpon successful completion,
33362187b41SDavid Xu.Fn posix_spawn
33462187b41SDavid Xuand
33562187b41SDavid Xu.Fn posix_spawnp
33662187b41SDavid Xureturn the process ID of the child process to the parent process,
33762187b41SDavid Xuin the variable pointed to by a non-NULL
33862187b41SDavid Xu.Fa pid
33962187b41SDavid Xuargument, and return zero as the function return value.
34062187b41SDavid XuOtherwise, no child process is created, no value is stored into
34162187b41SDavid Xuthe variable pointed to by
34262187b41SDavid Xu.Fa pid ,
34362187b41SDavid Xuand an error number is returned as the function return value to
34462187b41SDavid Xuindicate the error.
34562187b41SDavid XuIf the
34662187b41SDavid Xu.Fa pid
34762187b41SDavid Xuargument is a null pointer, the process ID of the child is not returned
34862187b41SDavid Xuto the caller.
34962187b41SDavid Xu.Sh ERRORS
35062187b41SDavid Xu.Bl -enum
35162187b41SDavid Xu.It
35262187b41SDavid XuIf
35362187b41SDavid Xu.Fn posix_spawn
35462187b41SDavid Xuand
35562187b41SDavid Xu.Fn posix_spawnp
35662187b41SDavid Xufail for any of the reasons that would cause
35762187b41SDavid Xu.Fn vfork
35862187b41SDavid Xuor one of the
35962187b41SDavid Xu.Nm exec
36062187b41SDavid Xuto fail, an error value is returned as described by
36162187b41SDavid Xu.Fn vfork
36262187b41SDavid Xuand
36362187b41SDavid Xu.Nm exec ,
36462187b41SDavid Xurespectively (or, if the error occurs after the calling process successfully
36562187b41SDavid Xureturns, the child process exits with exit status 127).
36662187b41SDavid Xu.It
36762187b41SDavid XuIf
36862187b41SDavid Xu.Nm POSIX_SPAWN_SETPGROUP
36962187b41SDavid Xuis set in the spawn-flags attribute of the object referenced by attrp, and
37062187b41SDavid Xu.Fn posix_spawn
37162187b41SDavid Xuor
37262187b41SDavid Xu.Fn posix_spawnp
37362187b41SDavid Xufails while changing the child's process group, an error value is returned as
37462187b41SDavid Xudescribed by
37562187b41SDavid Xu.Fn setpgid
37662187b41SDavid Xu(or, if the error occurs after the calling process successfully returns,
37762187b41SDavid Xuthe child process exits with exit status 127).
37862187b41SDavid Xu.It
37962187b41SDavid XuIf
38062187b41SDavid Xu.Nm POSIX_SPAWN_SETSCHEDPARAM
38162187b41SDavid Xuis set and
38262187b41SDavid Xu.Nm POSIX_SPAWN_SETSCHEDULER
38362187b41SDavid Xuis not set in the spawn-flags attribute of the object referenced by attrp, then
38462187b41SDavid Xuif
38562187b41SDavid Xu.Fn posix_spawn
38662187b41SDavid Xuor
38762187b41SDavid Xu.Fn posix_spawnp
38862187b41SDavid Xufails for any of the reasons that would cause
38962187b41SDavid Xu.Fn sched_setparam
39062187b41SDavid Xuto fail, an error value is returned as described by
39162187b41SDavid Xu.Fn sched_setparam
39262187b41SDavid Xu(or, if the error occurs after the calling process successfully returns, the
39362187b41SDavid Xuchild process exits with exit status 127).
39462187b41SDavid Xu.It
39562187b41SDavid XuIf
39662187b41SDavid Xu.Nm POSIX_SPAWN_SETSCHEDULER
39762187b41SDavid Xuis set in the spawn-flags attribute of the object referenced by attrp, and if
39862187b41SDavid Xu.Fn posix_spawn
39962187b41SDavid Xuor
40062187b41SDavid Xu.Fn posix_spawnp
40162187b41SDavid Xufails for any of the reasons that would cause
40262187b41SDavid Xu.Fn sched_setscheduler
40362187b41SDavid Xuto fail, an error value is returned as described by
40462187b41SDavid Xu.Fn sched_setscheduler
40562187b41SDavid Xu(or, if the error occurs after the calling process successfully returns,
40662187b41SDavid Xuthe child process exits with exit status 127).
40762187b41SDavid Xu.It
40862187b41SDavid XuIf the
40962187b41SDavid Xu.Fa file_actions
410876b6796SJilles Tjoelkerargument is not NULL, and specifies any dup2 or open actions to be
41162187b41SDavid Xuperformed, and if
41262187b41SDavid Xu.Fn posix_spawn
41362187b41SDavid Xuor
41462187b41SDavid Xu.Fn posix_spawnp
41562187b41SDavid Xufails for any of the reasons that would cause
416876b6796SJilles Tjoelker.Fn dup2
41762187b41SDavid Xuor
41862187b41SDavid Xu.Fn open
41962187b41SDavid Xuto fail, an error value is returned as described by
420876b6796SJilles Tjoelker.Fn dup2
42162187b41SDavid Xuand
42262187b41SDavid Xu.Fn open ,
42362187b41SDavid Xurespectively (or, if the error occurs after the calling process successfully
42462187b41SDavid Xureturns, the child process exits with exit status 127). An open file action
42562187b41SDavid Xumay, by itself, result in any of the errors described by
42662187b41SDavid Xu.Fn dup2 ,
42762187b41SDavid Xuin addition to those described by
42862187b41SDavid Xu.Fn open .
429876b6796SJilles TjoelkerThis implementation ignores any errors from
430876b6796SJilles Tjoelker.Fn close ,
431876b6796SJilles Tjoelkerincluding trying to close a descriptor that is not open.
43278963d79SKonstantin BelousovThe ignore extends to any errors from individual file descriptors
43378963d79SKonstantin Belousov.Fn close
43478963d79SKonstantin Belousovexecuted as part of the
43578963d79SKonstantin Belousov.Fn closefrom
43678963d79SKonstantin Belousovaction.
43762187b41SDavid Xu.El
43862187b41SDavid Xu.Sh SEE ALSO
43962187b41SDavid Xu.Xr close 2 ,
44062187b41SDavid Xu.Xr dup2 2 ,
44162187b41SDavid Xu.Xr execve 2 ,
44262187b41SDavid Xu.Xr fcntl 2 ,
44362187b41SDavid Xu.Xr open 2 ,
444a725a7a2SKonstantin Belousov.Xr procctl 2 ,
4450aee91e1SChristian Brueffer.Xr sched_setparam 2 ,
4460aee91e1SChristian Brueffer.Xr sched_setscheduler 2 ,
4470aee91e1SChristian Brueffer.Xr setpgid 2 ,
4480aee91e1SChristian Brueffer.Xr vfork 2 ,
449*6e1fc011SGraham Percival.Xr posix_spawn_file_actions_addchdir_np 3 ,
45062187b41SDavid Xu.Xr posix_spawn_file_actions_addclose 3 ,
45178963d79SKonstantin Belousov.Xr posix_spawn_file_actions_addclosefrom_np 3 ,
45262187b41SDavid Xu.Xr posix_spawn_file_actions_adddup2 3 ,
453bd44dce5SKonstantin Belousov.Xr posix_spawn_file_actions_addfchdir_np 3 ,
454*6e1fc011SGraham Percival.Xr posix_spawn_file_actions_addopen 3 ,
45562187b41SDavid Xu.Xr posix_spawn_file_actions_destroy 3 ,
45662187b41SDavid Xu.Xr posix_spawn_file_actions_init 3 ,
45762187b41SDavid Xu.Xr posix_spawnattr_destroy 3 ,
45862187b41SDavid Xu.Xr posix_spawnattr_getflags 3 ,
45962187b41SDavid Xu.Xr posix_spawnattr_getpgroup 3 ,
46062187b41SDavid Xu.Xr posix_spawnattr_getschedparam 3 ,
46162187b41SDavid Xu.Xr posix_spawnattr_getschedpolicy 3 ,
46262187b41SDavid Xu.Xr posix_spawnattr_getsigdefault 3 ,
46362187b41SDavid Xu.Xr posix_spawnattr_getsigmask 3 ,
46462187b41SDavid Xu.Xr posix_spawnattr_init 3 ,
46562187b41SDavid Xu.Xr posix_spawnattr_setflags 3 ,
46662187b41SDavid Xu.Xr posix_spawnattr_setpgroup 3 ,
46762187b41SDavid Xu.Xr posix_spawnattr_setschedparam 3 ,
46862187b41SDavid Xu.Xr posix_spawnattr_setschedpolicy 3 ,
46962187b41SDavid Xu.Xr posix_spawnattr_setsigdefault 3 ,
4700aee91e1SChristian Brueffer.Xr posix_spawnattr_setsigmask 3
47162187b41SDavid Xu.Sh STANDARDS
47262187b41SDavid XuThe
47362187b41SDavid Xu.Fn posix_spawn
47462187b41SDavid Xuand
47562187b41SDavid Xu.Fn posix_spawnp
47662187b41SDavid Xufunctions conform to
477876b6796SJilles Tjoelker.St -p1003.1-2001 ,
478876b6796SJilles Tjoelkerexcept that they ignore all errors from
479876b6796SJilles Tjoelker.Fn close .
480876b6796SJilles TjoelkerA future update of the Standard is expected to require that these functions
481876b6796SJilles Tjoelkernot fail because a file descriptor to be closed (via
482876b6796SJilles Tjoelker.Fn posix_spawn_file_actions_addclose )
483876b6796SJilles Tjoelkeris not open.
48462187b41SDavid Xu.Sh HISTORY
48562187b41SDavid XuThe
48662187b41SDavid Xu.Fn posix_spawn
48762187b41SDavid Xuand
48862187b41SDavid Xu.Fn posix_spawnp
48962187b41SDavid Xufunctions first appeared in
49062187b41SDavid Xu.Fx 8.0 .
49162187b41SDavid Xu.Sh AUTHORS
49218c5321dSBaptiste Daroussin.An \&Ed Schouten Aq Mt ed@FreeBSD.org
493