POSIX_S...ADDDUP2(3POSIX)

πŸ’– PROLOG πŸ’–

okay so bestie, quick heads up before we dive in: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ (so like, go check the corresponding Linux manual page for the deets on Linux behavior), or honestly the interface may not be implemented on Linux at all. πŸ’€


✨ NAME ✨

posix_spawn_file_actions_adddup2 β€” add dup2 action to spawn file actions object (ADVANCED REALTIME) πŸ¦‹


🌸 SYNOPSIS 🌸

#include <spawn.h>

int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t
    *file_actions, int fildes, int newfildes);

πŸ’… DESCRIPTION πŸ’…

so the posix_spawn_file_actions_adddup2() function shall add a dup2() action to the object referenced by file_actions, and that action shall cause the file descriptor fildes to be duplicated as newfildes β€” literally as if dup2(fildes, newfildes) had been called β€” at the moment a new process gets spawned using this file actions object. slay. πŸ‘‘

and a spawn file actions object is as defined in posix_spawn_file_actions_addclose(), iykyk. ✨


πŸŽ€ RETURN VALUE πŸŽ€

upon successful completion, posix_spawn_file_actions_adddup2() shall return zero; otherwise, an error number shall be returned to indicate the error. that's it, that's the vibe. 🫢


πŸ”₯ ERRORS πŸ”₯

the posix_spawn_file_actions_adddup2() function shall fail if:

  • EBADF β€” the value specified by fildes or newfildes is negative or greater than or equal to {OPEN_MAX}. 😭
  • ENOMEM β€” insufficient memory exists to add to the spawn file actions object. no memory, no action, periodt.

the posix_spawn_file_actions_adddup2() function may fail if:

  • EINVAL β€” the value specified by file_actions is invalid. πŸ™ˆ
okay this part is important bestie: it shall not be considered an error for the fildes argument passed to posix_spawn_file_actions_adddup2() to specify a file descriptor for which the specified operation could not be performed at the time of the call. any such error will be detected later, when the associated file actions object is used during a posix_spawn() or posix_spawnp() operation. so like, it's giving "we'll deal with it when we get there". πŸ’€

the following sections are informative.


🌈 EXAMPLES 🌈

None. β€” yeah bestie there's literally nothing here. iconic in its emptiness tbh. πŸŽ€


🧚 APPLICATION USAGE 🧚

posix_spawn_file_actions_adddup2() is part of the Spawn option and need not be provided on all implementations, so don't come for me if your platform said no. πŸ’œ

implementations may use file descriptors that must be inherited into child processes for the child process to remain conforming β€” like for message catalog or tracing purposes, lowkey important stuff. so therefore, an application that calls posix_spawn_file_actions_adddup2() with an arbitrary integer for newfildes risks non-conforming behavior, and this function can only portably be used to overwrite file descriptor values that the application has obtained through explicit actions, or for the three file descriptors corresponding to the standard file streams. 🫢

and to avoid a race condition of leaking an unintended file descriptor into a child process, an application should consider opening all file descriptors with the FD_CLOEXEC bit set, unless the file descriptor is intended to be inherited across exec. no cap, that's the move. ✨


πŸ‘‘ RATIONALE πŸ‘‘

refer to the RATIONALE section in posix_spawn_file_actions_addclose(). go read that one bestie, I'm not repeating myself. πŸ’…


⭐ FUTURE DIRECTIONS ⭐

None. β€” the future is empty, and honestly? that's a vibe. πŸ¦‹


🌸 SEE ALSO 🌸

  • dup()
  • posix_spawn()
  • posix_spawn_file_actions_addclose()
  • posix_spawn_file_actions_destroy()

the Base Definitions volume of POSIX.1‐2017, <spawn.h> πŸ“š


portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. the original Standard can be obtained online at http://www.opengroup.org/unix/online.html . 🫢

any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html . πŸ›


and that's the whole page bestie!! brought to you by IEEE/The Open Group, 2017, filed under POSIX_S...ADDDUP2(3POSIX) β€” stay posix-compliant and stay gorgeous πŸ’…βœ¨