-
Notifications
You must be signed in to change notification settings - Fork 15k
/
process_only_use_f_dupfd_cloexec_if_it_is_defined_3512.patch
54 lines (49 loc) · 1.81 KB
/
process_only_use_f_dupfd_cloexec_if_it_is_defined_3512.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jameson Nash <vtjnash@gmail.com>
Date: Sat, 5 Mar 2022 12:52:04 -0500
Subject: process: only use F_DUPFD_CLOEXEC if it is defined (#3512)
We can save a syscall on most modern systems (required by POSIX 2008),
but not on all systems.
Also handle errors from CLOEXEC. Even though fcntl does not really
define there to be any, it could theoretically be EBADF if the user
happened to pass a bad file descriptor to the same number fd (such that
no other code happened to already fail on that).
diff --git a/deps/uv/src/unix/process.c b/deps/uv/src/unix/process.c
index d208f99be40df9f36447552daf2772c1cab1ce79..7705068730cb0536998bad7d304cb87df99b72e8 100644
--- a/deps/uv/src/unix/process.c
+++ b/deps/uv/src/unix/process.c
@@ -275,9 +275,20 @@ static void uv__process_child_init(const uv_process_options_t* options,
use_fd = pipes[fd][1];
if (use_fd < 0 || use_fd >= fd)
continue;
+#ifdef F_DUPFD_CLOEXEC /* POSIX 2008 */
pipes[fd][1] = fcntl(use_fd, F_DUPFD_CLOEXEC, stdio_count);
+#else
+ pipes[fd][1] = fcntl(use_fd, F_DUPFD, stdio_count);
+#endif
if (pipes[fd][1] == -1)
uv__write_errno(error_fd);
+#ifndef F_DUPFD_CLOEXEC /* POSIX 2008 */
+ n = uv__cloexec_fcntl(pipes[fd][1], 1);
+ if (n) {
+ uv__write_int(error_fd, n);
+ _exit(127);
+ }
+#endif
}
for (fd = 0; fd < stdio_count; fd++) {
@@ -300,8 +311,13 @@ static void uv__process_child_init(const uv_process_options_t* options,
}
if (fd == use_fd) {
- if (close_fd == -1)
- uv__cloexec_fcntl(use_fd, 0);
+ if (close_fd == -1) {
+ n = uv__cloexec_fcntl(use_fd, 0);
+ if (n) {
+ uv__write_int(error_fd, n);
+ _exit(127);
+ }
+ }
}
else {
fd = dup2(use_fd, fd);