aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'io.c')
-rw-r--r--io.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/io.c b/io.c
index 6756782a..be6c462c 100644
--- a/io.c
+++ b/io.c
@@ -446,13 +446,15 @@ remap_std_file(int oldfd)
int newfd;
int ret = -1;
+ close(oldfd);
newfd = open("/dev/null", O_RDWR);
- if (newfd >= 0) {
- /* dup2() will close fileno(fp) for us first. */
+ if (newfd >= 0 && newfd != oldfd) {
+ /* dup2() will close oldfd for us first. */
ret = dup2(newfd, oldfd);
if (ret == 0)
close(newfd);
- }
+ } else
+ ret = 0;
return ret;
}