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.\" 3539e499a8SJilles Tjoelker.Dd May 9, 2013 3662187b41SDavid Xu.Dt POSIX_SPAWN_FILE_ACTIONS_ADDOPEN 3 3762187b41SDavid Xu.Os 3862187b41SDavid Xu.Sh NAME 3962187b41SDavid Xu.Nm posix_spawn_file_actions_addopen , 4062187b41SDavid Xu.Nm posix_spawn_file_actions_adddup2 , 41bd44dce5SKonstantin Belousov.Nm posix_spawn_file_actions_addclose , 4278963d79SKonstantin Belousov.Nm posix_spawn_file_actions_addclosefrom_np , 43bd44dce5SKonstantin Belousov.Nm posix_spawn_file_actions_addchdir_np , 44bd44dce5SKonstantin Belousov.Nm posix_spawn_file_actions_addfchdir_np 4578963d79SKonstantin Belousov.Nd "add open, dup2, close, closefrom, or chdir/fchdir actions to spawn file actions object" 4662187b41SDavid Xu.Sh LIBRARY 4762187b41SDavid Xu.Lb libc 4862187b41SDavid Xu.Sh SYNOPSIS 4962187b41SDavid Xu.In spawn.h 5062187b41SDavid Xu.Ft int 518ed1e4a5SKonstantin Belousov.Fo posix_spawn_file_actions_addopen 528ed1e4a5SKonstantin Belousov.Fa "posix_spawn_file_actions_t * file_actions" 538ed1e4a5SKonstantin Belousov.Fa "int fildes" 548ed1e4a5SKonstantin Belousov.Fa "const char *restrict path" 558ed1e4a5SKonstantin Belousov.Fa "int oflag" 568ed1e4a5SKonstantin Belousov.Fa "mode_t mode" 578ed1e4a5SKonstantin Belousov.Fc 5862187b41SDavid Xu.Ft int 598ed1e4a5SKonstantin Belousov.Fo posix_spawn_file_actions_adddup2 608ed1e4a5SKonstantin Belousov.Fa "posix_spawn_file_actions_t * file_actions" 618ed1e4a5SKonstantin Belousov.Fa "int fildes" 628ed1e4a5SKonstantin Belousov.Fa "int newfildes" 638ed1e4a5SKonstantin Belousov.Fc 6462187b41SDavid Xu.Ft int 658ed1e4a5SKonstantin Belousov.Fo posix_spawn_file_actions_addclose 668ed1e4a5SKonstantin Belousov.Fa "posix_spawn_file_actions_t * file_actions" 678ed1e4a5SKonstantin Belousov.Fa "int fildes" 688ed1e4a5SKonstantin Belousov.Fc 69bd44dce5SKonstantin Belousov.Ft int 7078963d79SKonstantin Belousov.Fo posix_spawn_file_actions_addclosefrom_np 7178963d79SKonstantin Belousov.Fa "posix_spawn_file_actions_t * file_actions" 7278963d79SKonstantin Belousov.Fa "int from" 7378963d79SKonstantin Belousov.Fc 7478963d79SKonstantin Belousov.Ft int 75bd44dce5SKonstantin Belousov.Fo posix_spawn_file_actions_addchdir_np 76bd44dce5SKonstantin Belousov.Fa "posix_spawn_file_actions_t *restrict file_actions" 77bd44dce5SKonstantin Belousov.Fa "const char *restrict path" 78bd44dce5SKonstantin Belousov.Fc 79bd44dce5SKonstantin Belousov.Ft int 80bd44dce5SKonstantin Belousov.Fo posix_spawn_file_actions_addfchdir_np 81bd44dce5SKonstantin Belousov.Fa "posix_spawn_file_actions_t * file_actions" 82bd44dce5SKonstantin Belousov.Fa "int fildes" 83bd44dce5SKonstantin Belousov.Fc 8462187b41SDavid Xu.Sh DESCRIPTION 8562187b41SDavid XuThese functions add an open, dup2 or close action to a spawn 8662187b41SDavid Xufile actions object. 8762187b41SDavid Xu.Pp 8862187b41SDavid XuA spawn file actions object is of type 8962187b41SDavid Xu.Vt posix_spawn_file_actions_t 9062187b41SDavid Xu(defined in 9162187b41SDavid Xu.In spawn.h ) 9262187b41SDavid Xuand is used to specify a series of actions to be performed by a 9362187b41SDavid Xu.Fn posix_spawn 9462187b41SDavid Xuor 9562187b41SDavid Xu.Fn posix_spawnp 9662187b41SDavid Xuoperation in order to arrive at the set of open file descriptors for the 9762187b41SDavid Xuchild process given the set of open file descriptors of the parent. 9862187b41SDavid Xu.Pp 9962187b41SDavid XuA spawn file actions object, when passed to 10062187b41SDavid Xu.Fn posix_spawn 10162187b41SDavid Xuor 10262187b41SDavid Xu.Fn posix_spawnp , 10362187b41SDavid Xuspecify how the set of open file descriptors in the calling 10462187b41SDavid Xuprocess is transformed into a set of potentially open file descriptors 10562187b41SDavid Xufor the spawned process. 10662187b41SDavid XuThis transformation is as if the specified sequence of actions was 10762187b41SDavid Xuperformed exactly once, in the context of the spawned process (prior to 10862187b41SDavid Xuexecution of the new process image), in the order in which the actions 10962187b41SDavid Xuwere added to the object; additionally, when the new process image is 11062187b41SDavid Xuexecuted, any file descriptor (from this new set) which has its 11162187b41SDavid Xu.Dv FD_CLOEXEC 11262187b41SDavid Xuflag set is closed (see 11362187b41SDavid Xu.Fn posix_spawn ) . 11462187b41SDavid Xu.Pp 11562187b41SDavid XuThe 11662187b41SDavid Xu.Fn posix_spawn_file_actions_addopen 11762187b41SDavid Xufunction adds an open action to the object referenced by 11862187b41SDavid Xu.Fa file_actions 11962187b41SDavid Xuthat causes the file named by 12062187b41SDavid Xu.Fa path 12162187b41SDavid Xuto be opened (as if 12262187b41SDavid Xu.Bd -literal -offset indent 12362187b41SDavid Xuopen(path, oflag, mode) 12462187b41SDavid Xu.Ed 12562187b41SDavid Xu.Pp 12662187b41SDavid Xuhad been called, and the returned file descriptor, if not 12762187b41SDavid Xu.Fa fildes , 12862187b41SDavid Xuhad been changed to 12962187b41SDavid Xu.Fa fildes ) 13062187b41SDavid Xuwhen a new process is spawned using this file actions object. 13162187b41SDavid XuIf 13262187b41SDavid Xu.Fa fildes 13362187b41SDavid Xuwas already an open file descriptor, it is closed before the new 13462187b41SDavid Xufile is opened. 13562187b41SDavid Xu.Pp 13662187b41SDavid XuThe string described by 13762187b41SDavid Xu.Fa path 13862187b41SDavid Xuis copied by the 13962187b41SDavid Xu.Fn posix_spawn_file_actions_addopen 14062187b41SDavid Xufunction. 14162187b41SDavid Xu.Pp 14262187b41SDavid XuThe 14362187b41SDavid Xu.Fn posix_spawn_file_actions_adddup2 14462187b41SDavid Xufunction adds a dup2 action to the object referenced by 14562187b41SDavid Xu.Fa file_actions 14662187b41SDavid Xuthat causes the file descriptor 14762187b41SDavid Xu.Fa fildes 14862187b41SDavid Xuto be duplicated as 14962187b41SDavid Xu.Fa newfildes 15062187b41SDavid Xu(as if 15162187b41SDavid Xu.Bd -literal -offset indent 15262187b41SDavid Xudup2(fildes, newfildes) 15362187b41SDavid Xu.Ed 15462187b41SDavid Xu.Pp 15538cf77deSJilles Tjoelkerhad been called) when a new process is spawned using this file actions object, 15638cf77deSJilles Tjoelkerexcept that the 15738cf77deSJilles Tjoelker.Dv FD_CLOEXEC 15838cf77deSJilles Tjoelkerflag for 15938cf77deSJilles Tjoelker.Fa newfildes 16038cf77deSJilles Tjoelkeris cleared even if 16138cf77deSJilles Tjoelker.Fa fildes 16238cf77deSJilles Tjoelkeris equal to 16338cf77deSJilles Tjoelker.Fa newfildes . 16438cf77deSJilles TjoelkerThe difference from 16538cf77deSJilles Tjoelker.Fn dup2 16638cf77deSJilles Tjoelkeris useful for passing a particular file descriptor 16738cf77deSJilles Tjoelkerto a particular child process. 16862187b41SDavid Xu.Pp 16962187b41SDavid XuThe 17062187b41SDavid Xu.Fn posix_spawn_file_actions_addclose 17162187b41SDavid Xufunction adds a close action to the object referenced by 17262187b41SDavid Xu.Fa file_actions 17362187b41SDavid Xuthat causes the file descriptor 17462187b41SDavid Xu.Fa fildes 17562187b41SDavid Xuto be closed (as if 17662187b41SDavid Xu.Bd -literal -offset indent 17762187b41SDavid Xuclose(fildes) 17862187b41SDavid Xu.Ed 17962187b41SDavid Xu.Pp 18062187b41SDavid Xuhad been called) when a new process is spawned using this file actions 18162187b41SDavid Xuobject. 182bd44dce5SKonstantin Belousov.Pp 183bd44dce5SKonstantin BelousovThe 18478963d79SKonstantin Belousov.Fn posix_spawn_file_actions_addclosefrom_np 18578963d79SKonstantin Belousovfunction adds a close action to close all file descriptors numerically 18678963d79SKonstantin Belousovequal or greater then the argument 18778963d79SKonstantin Belousov.Fa from . 18878963d79SKonstantin BelousovFor each open file descriptor, logically the close action is performed, 18978963d79SKonstantin Belousovand any possible errors encountered are ignored. 19078963d79SKonstantin Belousov.Pp 19178963d79SKonstantin BelousovThe 192bd44dce5SKonstantin Belousov.Fn posix_spawn_file_actions_addchdir_np 193bd44dce5SKonstantin Belousovand 194bd44dce5SKonstantin Belousov.Fn posix_spawn_file_actions_addfchdir_np 195bd44dce5SKonstantin Belousovfunctions add a change current directory action to the object 196bd44dce5SKonstantin Belousovreferenced by 197bd44dce5SKonstantin Belousov.Fa file_actions 198bd44dce5SKonstantin Belousovthat affects actions (opens with relative path) performed after the operation, 199bd44dce5SKonstantin Belousovin the order of insertion into the 200bd44dce5SKonstantin Belousov.Fa file_actions 201bd44dce5SKonstantin Belousovobject. 202bd44dce5SKonstantin BelousovIt also sets the working directory for the spawned program. 203bd44dce5SKonstantin BelousovThe 204bd44dce5SKonstantin Belousov.Fn posix_spawn_file_actions_addchdir_np 205bd44dce5SKonstantin Belousovfunction takes the 206bd44dce5SKonstantin Belousov.Fa path 207bd44dce5SKonstantin Belousovto set as the working directory, while 208bd44dce5SKonstantin Belousov.Fn posix_spawn_file_actions_addfchdir_np 209bd44dce5SKonstantin Belousovtakes the directory file descriptor. 21062187b41SDavid Xu.Sh RETURN VALUES 21162187b41SDavid XuUpon successful completion, these functions return zero; 21262187b41SDavid Xuotherwise, an error number is returned to indicate the error. 21362187b41SDavid Xu.Sh ERRORS 21462187b41SDavid XuThese 21562187b41SDavid Xufunctions fail if: 21662187b41SDavid Xu.Bl -tag -width Er 21739e499a8SJilles Tjoelker.It Bq Er EBADF 21862187b41SDavid XuThe value specified by 21962187b41SDavid Xu.Fa fildes 22062187b41SDavid Xuor 22162187b41SDavid Xu.Fa newfildes 22262187b41SDavid Xuis negative. 22362187b41SDavid Xu.It Bq Er ENOMEM 22462187b41SDavid XuInsufficient memory exists to add to the spawn file actions object. 22562187b41SDavid Xu.El 22662187b41SDavid Xu.Sh SEE ALSO 22762187b41SDavid Xu.Xr close 2 , 22862187b41SDavid Xu.Xr dup2 2 , 22962187b41SDavid Xu.Xr open 2 , 23062187b41SDavid Xu.Xr posix_spawn 3 , 23162187b41SDavid Xu.Xr posix_spawn_file_actions_destroy 3 , 23262187b41SDavid Xu.Xr posix_spawn_file_actions_init 3 , 23362187b41SDavid Xu.Xr posix_spawnp 3 23462187b41SDavid Xu.Sh STANDARDS 23562187b41SDavid XuThe 23662187b41SDavid Xu.Fn posix_spawn_file_actions_addopen , 23762187b41SDavid Xu.Fn posix_spawn_file_actions_adddup2 23862187b41SDavid Xuand 23962187b41SDavid Xu.Fn posix_spawn_file_actions_addclose 24062187b41SDavid Xufunctions conform to 24138cf77deSJilles Tjoelker.St -p1003.1-2001 , 24238cf77deSJilles Tjoelkerwith the exception of the behavior of 24338cf77deSJilles Tjoelker.Fn posix_spawn_file_actions_adddup2 24438cf77deSJilles Tjoelkerif 24538cf77deSJilles Tjoelker.Fa fildes 24638cf77deSJilles Tjoelkeris equal to 24738cf77deSJilles Tjoelker.Fa newfildes 24838cf77deSJilles Tjoelker(clearing 24938cf77deSJilles Tjoelker.Dv FD_CLOEXEC ) . 250b6dd1732SSergey KandaurovA future update of the Standard is expected to require this behavior. 251bd44dce5SKonstantin Belousov.Pp 252bd44dce5SKonstantin BelousovThe 25378963d79SKonstantin Belousov.Fn posix_spawn_file_actions_addchdir_np , 25478963d79SKonstantin Belousov.Fn posix_spawn_file_actions_addfchdir_np , 255bd44dce5SKonstantin Belousovand 25678963d79SKonstantin Belousov.Fn posix_spawn_file_actions_addclosefrom_np 257bd44dce5SKonstantin Belousovfunctions are non-standard functions implemented after the similar 258bd44dce5SKonstantin Belousovfunctionality provided by glibc. 25962187b41SDavid Xu.Sh HISTORY 26062187b41SDavid XuThe 26162187b41SDavid Xu.Fn posix_spawn_file_actions_addopen , 26262187b41SDavid Xu.Fn posix_spawn_file_actions_adddup2 26362187b41SDavid Xuand 26462187b41SDavid Xu.Fn posix_spawn_file_actions_addclose 26562187b41SDavid Xufunctions first appeared in 26662187b41SDavid Xu.Fx 8.0 . 267bd44dce5SKonstantin BelousovThe 26878963d79SKonstantin Belousov.Fn posix_spawn_file_actions_addchdir_np , 26978963d79SKonstantin Belousov.Fn posix_spawn_file_actions_addfchdir_np , 270bd44dce5SKonstantin Belousovand 27178963d79SKonstantin Belousov.Fn posix_spawn_file_actions_addclosefrom_np 272bd44dce5SKonstantin Belousovfunctions first appeared in 273*ba719a0fSTom Hukins.Fx 13.1 . 27462187b41SDavid Xu.Sh AUTHORS 27518c5321dSBaptiste Daroussin.An \&Ed Schouten Aq Mt ed@FreeBSD.org 276