Skip to content

Commit f47c869

Browse files
committed
Use POSIX_SPAWN_CLOEXEC_DEFAULT in posix_spawn.c when available
1 parent b95e5fb commit f47c869

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
@@ -96,9 +96,15 @@ do_spawn_posix (char *const args[],
9696
if (childGroup || childUser) {
9797
return -2;
9898
}
99+
100+
short spawn_flags = 0;
101+
99102
if ((flags & RUN_PROCESS_IN_CLOSE_FDS) != 0) {
100-
// TODO: can this be efficiently supported?
103+
#if defined(HAVE_POSIX_SPAWN_CLOEXEC_DEFAULT)
104+
spawn_flags |= POSIX_SPAWN_CLOEXEC_DEFAULT;
105+
#else
101106
return -2;
107+
#endif
102108
}
103109

104110
// Now the main act...
@@ -107,7 +113,6 @@ do_spawn_posix (char *const args[],
107113
posix_spawnattr_t sa;
108114
int r;
109115
ProcHandle ret;
110-
short spawn_flags = 0;
111116

112117
r = posix_spawn_file_actions_init(&fa);
113118
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)