From 702e49eeb5654b6881f91618e5bc95853e206b6c Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 21 Nov 2019 15:30:01 +0100 Subject: forkfd: add FFD_USE_FORK to force use of fork() Change-Id: Ia2aa807ffa8a4c798425fffd15d933e47919247a Reviewed-by: Oswald Buddenhagen --- src/3rdparty/forkfd/forkfd.c | 14 +++++++++++--- src/3rdparty/forkfd/forkfd.h | 5 +++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/3rdparty/forkfd/forkfd.c b/src/3rdparty/forkfd/forkfd.c index 2ae85d6f37..31189fa2cd 100644 --- a/src/3rdparty/forkfd/forkfd.c +++ b/src/3rdparty/forkfd/forkfd.c @@ -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); diff --git a/src/3rdparty/forkfd/forkfd.h b/src/3rdparty/forkfd/forkfd.h index eb121de593..fe70371719 100644 --- a/src/3rdparty/forkfd/forkfd.h +++ b/src/3rdparty/forkfd/forkfd.h @@ -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) -- cgit v1.2.3