Skip to content

Commit a8ef799

Browse files
authored
Merge pull request #254 from codedownio/posix-spawn-cloexec-default
Use POSIX_SPAWN_CLOEXEC_DEFAULT in posix_spawn.c when available
2 parents e8a2fbc + f47c869 commit a8ef799

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

cbits/posix/posix_spawn.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,15 @@ do_spawn_posix (char *const args[],
108108
if (childGroup || childUser) {
109109
return -2;
110110
}
111+
112+
short spawn_flags = 0;
113+
111114
if ((flags & RUN_PROCESS_IN_CLOSE_FDS) != 0) {
112-
// TODO: can this be efficiently supported?
115+
#if defined(HAVE_POSIX_SPAWN_CLOEXEC_DEFAULT)
116+
spawn_flags |= POSIX_SPAWN_CLOEXEC_DEFAULT;
117+
#else
113118
return -2;
119+
#endif
114120
}
115121

116122
// Now the main act...
@@ -119,7 +125,6 @@ do_spawn_posix (char *const args[],
119125
posix_spawnattr_t sa;
120126
int r;
121127
ProcHandle ret;
122-
short spawn_flags = 0;
123128

124129
r = posix_spawn_file_actions_init(&fa);
125130
if (r != 0) {

configure.ac

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ AC_CHECK_DECLS([POSIX_SPAWN_SETSID, POSIX_SPAWN_SETSID_NP],[],[],[
2626
#define _GNU_SOURCE
2727
#include <spawn.h>
2828
])
29+
AC_CHECK_DECLS([POSIX_SPAWN_CLOEXEC_DEFAULT],[],[],[
30+
#define _GNU_SOURCE
31+
#include <spawn.h>
32+
])
2933
AC_CHECK_DECLS([POSIX_SPAWN_SETPGROUP],[],[],[
3034
#define _GNU_SOURCE
3135
#include <spawn.h>

0 commit comments

Comments
 (0)