File tree Expand file tree Collapse file tree 1 file changed +11
-17
lines changed
Expand file tree Collapse file tree 1 file changed +11
-17
lines changed Original file line number Diff line number Diff line change @@ -107,23 +107,17 @@ setup_std_handle_fork(int fd,
107107 * errors. See #266.
108108 */
109109int 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- return -1 ;
124- }
125- }
126- return fd ;
110+ if (fd > 2 ) {
111+ return fd ;
112+ }
113+
114+ int new_fd = fcntl (fd , F_DUPFD , 3 );
115+ if (new_fd == -1 ) {
116+ * failed_doing = "fcntl(F_DUP_FD)" ;
117+ return -1 ;
118+ }
119+ close (fd );
120+ return new_fd ;
127121}
128122
129123/* Try spawning with fork. */
You can’t perform that action at this time.
0 commit comments