aboutsummaryrefslogtreecommitdiff
path: root/libc/bionic/spawn.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libc/bionic/spawn.cpp')
-rw-r--r--libc/bionic/spawn.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/libc/bionic/spawn.cpp b/libc/bionic/spawn.cpp
index 314a05669..59f763138 100644
--- a/libc/bionic/spawn.cpp
+++ b/libc/bionic/spawn.cpp
@@ -30,10 +30,12 @@
#include <errno.h>
#include <fcntl.h>
+#include <linux/close_range.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <sys/resource.h>
+#include <sys/syscall.h>
#include <unistd.h>
#include <android/fdsan.h>
@@ -49,6 +51,9 @@ static int set_cloexec(int i) {
// mark all open fds except stdin/out/err as close-on-exec
static int cloexec_except_stdioe() {
+ // requires 5.11+ or ACK 5.10-T kernel, otherwise returns ENOSYS or EINVAL
+ if (!syscall(SYS_close_range, 3, ~0U, CLOSE_RANGE_CLOEXEC)) return 0;
+
// unfortunately getrlimit can lie:
// - both soft and hard limits can be lowered to 0, with fds still open, so it can underestimate
// - in practice it usually is some really large value (like 32K or more)