File tree Expand file tree Collapse file tree 1 file changed +17
-18
lines changed
Expand file tree Collapse file tree 1 file changed +17
-18
lines changed Original file line number Diff line number Diff line change @@ -107,24 +107,23 @@ setup_std_handle_fork(int fd,
107107 * errors. See #266.
108108 */
109109int unshadow_pipe_fd (int fd , char * * failed_doing ) {
110- if (fd <= 2 ) {
111- int fd2 = dup (fd );
112- if (fd2 == -1 ) {
113- * failed_doing = "dup(unshadow)" ;
114- return -1 ;
115- }
116-
117- // This should recurse at most three times
118- int fd3 = unshadow_pipe_fd (fd2 , failed_doing );
119- if (close (fd2 ) == -1 ) {
120- * failed_doing = "close(unshadow)" ;
121- return -1 ;
122- }
123-
124- return fd3 ;
125- } else {
126- return fd ;
127- }
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 ;
128127}
129128
130129/* Try spawning with fork. */
You can’t perform that action at this time.
0 commit comments