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) {
261
261
goto start_fail ;
262
262
}
263
263
264
+
264
265
if ((pid = fork ()) < 0 ) {
265
266
print ( ERROR , "fork: %s" , strerror (errno ) );
266
267
goto start_fail ;
@@ -271,28 +272,39 @@ message *on_cmd_start(conn_node *conn, message *msg) {
271
272
close (pout [0 ]);
272
273
close (perr [0 ]);
273
274
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
+ }
280
285
281
286
if (h -> workdir )
282
287
chdir (h -> workdir );
283
288
284
289
dup2 (pin [0 ], STDIN_FILENO );
285
- dup2 (pout [1 ], STDOUT_FILENO );
286
- dup2 (perr [1 ], STDERR_FILENO );
287
-
288
- close (i );
290
+
289
291
close (pin [0 ]);
292
+
293
+ dup2 (pout [1 ], STDOUT_FILENO );
294
+
290
295
close (pout [1 ]);
296
+
297
+ dup2 (perr [1 ], STDERR_FILENO );
298
+
291
299
close (perr [1 ]);
292
300
293
301
execvp (argv [0 ], argv );
294
302
i = errno ;
303
+
295
304
write (pexec [1 ], & i , sizeof (int ));
305
+ close (STDIN_FILENO );
306
+ close (STDOUT_FILENO );
307
+ close (STDERR_FILENO );
296
308
close (pexec [1 ]);
297
309
exit (-1 );
298
310
} else {
You can’t perform that action at this time.
0 commit comments