1POSIX_SPAWN_FILE_ACTIONS_ADDPDOUSPI2X(3PPr)ogrammerP'OsSIMXa_nSuPaAlWN_FILE_ACTIONS_ADDDUP2(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       posix_spawn_file_actions_adddup2  —  add  dup2  action  to  spawn  file
13       actions object (ADVANCED REALTIME)
14

SYNOPSIS

16       #include <spawn.h>
17
18       int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t
19           *file_actions, int fildes, int newfildes);
20

DESCRIPTION

22       The  posix_spawn_file_actions_adddup2()  function  shall  add  a dup2()
23       action to the object referenced by file_actions that  shall  cause  the
24       file   descriptor   fildes   to  be  duplicated  as  newfildes  (as  if
25       dup2(fildes, newfildes) had been called) when a new process is  spawned
26       using this file actions object.
27
28       A     spawn     file     actions    object    is    as    defined    in
29       posix_spawn_file_actions_addclose().
30

RETURN VALUE

32       Upon  successful  completion,  the   posix_spawn_file_actions_adddup2()
33       function  shall  return  zero;  otherwise,  an  error  number  shall be
34       returned to indicate the error.
35

ERRORS

37       The posix_spawn_file_actions_adddup2() function shall fail if:
38
39       EBADF  The value specified  by  fildes  or  newfildes  is  negative  or
40              greater than or equal to {OPEN_MAX}.
41
42       ENOMEM Insufficient  memory  exists  to  add  to the spawn file actions
43              object.
44
45       The posix_spawn_file_actions_adddup2() function may fail if:
46
47       EINVAL The value specified by file_actions is invalid.
48
49       It shall not be considered an error for the fildes argument  passed  to
50       the  posix_spawn_file_actions_adddup2()  function  to  specify  a  file
51       descriptor for which the specified operation could not be performed  at
52       the  time of the call. Any such error will be detected when the associ‐
53       ated file actions object  is  later  used  during  a  posix_spawn()  or
54       posix_spawnp() operation.
55
56       The following sections are informative.
57

EXAMPLES

59       None.
60

APPLICATION USAGE

62       The  posix_spawn_file_actions_adddup2()  function  is part of the Spawn
63       option and need not be provided on all implementations.
64
65       Implementations may use file descriptors that must  be  inherited  into
66       child processes for the child process to remain conforming, such as for
67       message catalog or tracing purposes.  Therefore,  an  application  that
68       calls  posix_spawn_file_actions_adddup2() with an arbitrary integer for
69       newfildes risks non-conforming behavior, and  this  function  can  only
70       portably  be used to overwrite file descriptor values that the applica‐
71       tion has obtained through explicit  actions,  or  for  the  three  file
72       descriptors  corresponding  to  the  standard file streams. In order to
73       avoid a race condition of leaking an unintended file descriptor into  a
74       child process, an application should consider opening all file descrip‐
75       tors with the FD_CLOEXEC bit set unless the file descriptor is intended
76       to be inherited across exec.
77

RATIONALE

79       Refer to the RATIONALE section in posix_spawn_file_actions_addclose().
80

FUTURE DIRECTIONS

82       None.
83

SEE ALSO

85       dup(),        posix_spawn(),       posix_spawn_file_actions_addclose(),
86       posix_spawn_file_actions_destroy()
87
88       The Base Definitions volume of POSIX.1‐2017, <spawn.h>
89
91       Portions of this text are reprinted and reproduced in  electronic  form
92       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
93       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
94       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
95       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
96       event of any discrepancy between this version and the original IEEE and
97       The Open Group Standard, the original IEEE and The Open Group  Standard
98       is  the  referee document. The original Standard can be obtained online
99       at http://www.opengroup.org/unix/online.html .
100
101       Any typographical or formatting errors that appear  in  this  page  are
102       most likely to have been introduced during the conversion of the source
103       files to man page format. To report such errors,  see  https://www.ker
104       nel.org/doc/man-pages/reporting_bugs.html .
105
106
107
108IEEE/The Open Group                  2017 POSIX_SPAWN_FILE_ACTIONS_ADDDUP2(3P)
Impressum