diff --git a/cbits/posix/posix_spawn.c b/cbits/posix/posix_spawn.c index edd76c13..bf6dd9c4 100644 --- a/cbits/posix/posix_spawn.c +++ b/cbits/posix/posix_spawn.c @@ -96,9 +96,15 @@ do_spawn_posix (char *const args[], if (childGroup || childUser) { return -2; } + + short spawn_flags = 0; + if ((flags & RUN_PROCESS_IN_CLOSE_FDS) != 0) { - // TODO: can this be efficiently supported? +#if defined(HAVE_POSIX_SPAWN_CLOEXEC_DEFAULT) + spawn_flags |= POSIX_SPAWN_CLOEXEC_DEFAULT; +#else return -2; +#endif } // Now the main act... @@ -107,7 +113,6 @@ do_spawn_posix (char *const args[], posix_spawnattr_t sa; int r; ProcHandle ret; - short spawn_flags = 0; r = posix_spawn_file_actions_init(&fa); if (r != 0) { diff --git a/configure.ac b/configure.ac index 348952f7..d0874ef1 100644 --- a/configure.ac +++ b/configure.ac @@ -26,6 +26,10 @@ AC_CHECK_DECLS([POSIX_SPAWN_SETSID, POSIX_SPAWN_SETSID_NP],[],[],[ #define _GNU_SOURCE #include ]) +AC_CHECK_DECLS([POSIX_SPAWN_CLOEXEC_DEFAULT],[],[],[ + #define _GNU_SOURCE + #include +]) AC_CHECK_DECLS([POSIX_SPAWN_SETPGROUP],[],[],[ #define _GNU_SOURCE #include