diff options
author | Steve Bennett <steveb@workware.net.au> | 2021-07-02 19:51:43 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2021-07-02 19:55:16 +1000 |
commit | 40298deee7cd1e72cb5e34ef98e07bc6adff2573 (patch) | |
tree | e4dcb90029ba3a446ebf3aabe8d017c1afc3dfcf | |
parent | bcd4434161897da5203cdfaef8b2227e15d82c45 (diff) | |
download | jimtcl-40298deee7cd1e72cb5e34ef98e07bc6adff2573.zip jimtcl-40298deee7cd1e72cb5e34ef98e07bc6adff2573.tar.gz jimtcl-40298deee7cd1e72cb5e34ef98e07bc6adff2573.tar.bz2 |
exec: support stdin fd being closed
Don't try to dup2() a file descriptor that is already
correct. This can happen if, for example, stdin is closed
and exec redirects stdin from a file, thus opening the input
as file descriptor 0.
Fixes #201
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r-- | jim-exec.c | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -1046,17 +1046,17 @@ badargs: if (pid == 0) { /* Child */ /* Set up stdin, stdout, stderr */ - if (inputId != -1) { + if (inputId != -1 && inputId != fileno(stdin)) { dup2(inputId, fileno(stdin)); close(inputId); } - if (outputId != -1) { + if (outputId != -1 && outputId != fileno(stdout)) { dup2(outputId, fileno(stdout)); if (outputId != errorId) { close(outputId); } } - if (errorId != -1) { + if (errorId != -1 && errorId != fileno(stderr)) { dup2(errorId, fileno(stderr)); close(errorId); } |