forkfd: add FFD_USE_FORK to force use of fork()

Change-Id: Ia2aa807ffa8a4c798425fffd15d933e47919247a
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
This commit is contained in:
Thiago Macieira 2019-11-21 15:30:01 +01:00
parent 079fbebb6a
commit 702e49eeb5
2 changed files with 14 additions and 5 deletions

View File

@ -586,6 +586,12 @@ static int create_pipe(int filedes[], int flags)
* descriptor. You probably want to set this flag, since forkfd() does not work
* if the original parent process dies.
*
* @li @C FFD_USE_FORK Tell forkfd() to actually call fork() instead of a
* different system implementation that may be available. On systems where a
* different implementation is available, its behavior may differ from that of
* fork(), such as not calling the functions registered with pthread_atfork().
* If that's necessary, pass this flag.
*
* The file descriptor returned by forkfd() supports the following operations:
*
* @li read(2) When the child process exits, then the buffer supplied to
@ -613,9 +619,11 @@ int forkfd(int flags, pid_t *ppid)
int efd;
#endif
fd = system_forkfd(flags, ppid, &ret);
if (ret)
return fd;
if ((flags & FFD_USE_FORK) == 0) {
fd = system_forkfd(flags, ppid, &ret);
if (ret)
return fd;
}
(void) pthread_once(&forkfd_initialization, forkfd_initialize);

View File

@ -38,8 +38,9 @@
extern "C" {
#endif
#define FFD_CLOEXEC 1
#define FFD_NONBLOCK 2
#define FFD_CLOEXEC 1
#define FFD_NONBLOCK 2
#define FFD_USE_FORK 4
#define FFD_CHILD_PROCESS (-2)