File tree Expand file tree Collapse file tree 1 file changed +22
-10
lines changed
Expand file tree Collapse file tree 1 file changed +22
-10
lines changed Original file line number Diff line number Diff line change @@ -261,6 +261,7 @@ message *on_cmd_start(conn_node *conn, message *msg) {
261261 goto start_fail ;
262262 }
263263
264+
264265 if ((pid = fork ()) < 0 ) {
265266 print ( ERROR , "fork: %s" , strerror (errno ) );
266267 goto start_fail ;
@@ -271,28 +272,39 @@ message *on_cmd_start(conn_node *conn, message *msg) {
271272 close (pout [0 ]);
272273 close (perr [0 ]);
273274
274- i = open ("/dev/null" , O_RDWR );
275-
276- if (pin [0 ] == -1 )
277- pin [0 ] = i ;
278- if (pout [1 ] == -1 )
279- pout [1 ] = i ;
275+ if (pin [0 ] == -1 || pout [1 ] == -1 ) {
276+ i = open ("/dev/null" , O_RDWR );
277+
278+ if (pin [0 ] == -1 )
279+ pin [0 ] = dup (i );
280+ if (pout [1 ] == -1 )
281+ pout [1 ] = dup (i );
282+
283+ close (i );
284+ }
280285
281286 if (h -> workdir )
282287 chdir (h -> workdir );
283288
284289 dup2 (pin [0 ], STDIN_FILENO );
285- dup2 (pout [1 ], STDOUT_FILENO );
286- dup2 (perr [1 ], STDERR_FILENO );
287-
288- close (i );
290+
289291 close (pin [0 ]);
292+
293+ dup2 (pout [1 ], STDOUT_FILENO );
294+
290295 close (pout [1 ]);
296+
297+ dup2 (perr [1 ], STDERR_FILENO );
298+
291299 close (perr [1 ]);
292300
293301 execvp (argv [0 ], argv );
294302 i = errno ;
303+
295304 write (pexec [1 ], & i , sizeof (int ));
305+ close (STDIN_FILENO );
306+ close (STDOUT_FILENO );
307+ close (STDERR_FILENO );
296308 close (pexec [1 ]);
297309 exit (-1 );
298310 } else {
You can’t perform that action at this time.
0 commit comments