aboutsummaryrefslogtreecommitdiff
path: root/jim-exec.c
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2021-07-02 19:51:43 +1000
committerSteve Bennett <steveb@workware.net.au>2021-07-02 19:55:16 +1000
commit40298deee7cd1e72cb5e34ef98e07bc6adff2573 (patch)
treee4dcb90029ba3a446ebf3aabe8d017c1afc3dfcf /jim-exec.c
parentbcd4434161897da5203cdfaef8b2227e15d82c45 (diff)
downloadjimtcl-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>
Diffstat (limited to 'jim-exec.c')
-rw-r--r--jim-exec.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/jim-exec.c b/jim-exec.c
index 5a21a1f..22bbdb8 100644
--- a/jim-exec.c
+++ b/jim-exec.c
@@ -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);
}