From 93cb98417470d7172ac31df2c12634c5969c43e7 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 13 Mar 2015 23:53:35 -0700 Subject: forkfd: introduce system_forkfd to do system calls that do forkfd This is just to make the code cleaner. The static variable will control whether we've detected that the system call exists -- if it does, we are expected to always use it. Change-Id: Iee8cbc07c4434ce9b560ffff13cb4adc049413c1 Reviewed-by: Oswald Buddenhagen Reviewed-by: Rafael Roquetto --- src/3rdparty/forkfd/forkfd.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/3rdparty') diff --git a/src/3rdparty/forkfd/forkfd.c b/src/3rdparty/forkfd/forkfd.c index 5d62f88149..39eeb6a202 100644 --- a/src/3rdparty/forkfd/forkfd.c +++ b/src/3rdparty/forkfd/forkfd.c @@ -500,6 +500,14 @@ static int create_pipe(int filedes[], int flags) return ret; } +static const int system_has_forkfd = 0; +static int system_forkfd(int flags, pid_t *ppid) +{ + (void)flags; + (void)ppid; + return -1; +} + #ifndef FORKFD_NO_FORKFD /** * @brief forkfd returns a file descriptor representing a child process @@ -547,6 +555,12 @@ int forkfd(int flags, pid_t *ppid) int efd; #endif + if (system_has_forkfd) { + ret = system_forkfd(flags, ppid); + if (system_has_forkfd) + return ret; + } + (void) pthread_once(&forkfd_initialization, forkfd_initialize); info = allocateInfo(&header); @@ -670,6 +684,8 @@ int spawnfd(int flags, pid_t *ppid, const char *path, const posix_spawn_file_act /* we can only do work if we have a way to start the child in stopped mode; * otherwise, we have a major race condition. */ + assert(!system_has_forkfd); + (void) pthread_once(&forkfd_initialization, forkfd_initialize); info = allocateInfo(&header); -- cgit v1.2.3