We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ec45621 commit c25afa9Copy full SHA for c25afa9
cbits/posix/fork_exec.c
@@ -107,23 +107,17 @@ setup_std_handle_fork(int fd,
107
* errors. See #266.
108
*/
109
int unshadow_pipe_fd(int fd, char **failed_doing) {
110
- int i = 0;
111
- int fds[3] = {0};
112
- for (i = 0; fd < 3 && i < 3; ++i) {
113
- fds[i] = fd;
114
- fd = dup(fd);
115
- if (fd == -1) {
116
- *failed_doing = "dup(unshadow)";
117
- return -1;
118
- }
119
120
- for (int j = 0; j < i; ++j) {
121
- if (close(fds[j]) == -1) {
122
- *failed_doing = "close(unshadow)";
123
124
125
126
- return fd;
+ if (fd > 2) {
+ return fd;
+ }
+
+ int new_fd = fcntl(fd, F_DUPFD, 3);
+ if (new_fd == -1) {
+ *failed_doing = "fcntl(F_DUP_FD)";
+ return -1;
+ close(fd);
+ return new_fd;
127
}
128
129
/* Try spawning with fork. */
0 commit comments