From aaf792357da5d9aaa0f8f61da78daf12508a69c4 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Sun, 17 Feb 2002 14:51:29 +0100 Subject: Fixed closing all unused file descriptors when opening a pipe --- CONTRIBUTORS | 1 + HISTORY | 2 ++ thread.c | 9 ++++++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 8d4b3030..038dc88d 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -143,6 +143,7 @@ Artur Skawina Werner Fink for making I/O more robust by handling EINTR + for fixing closing all unused file descriptors when opening a pipe Rolf Hakenes for providing 'libdtv' and adapting the EIT mechanisms to it diff --git a/HISTORY b/HISTORY index 50f3ad98..7c9b0e27 100644 --- a/HISTORY +++ b/HISTORY @@ -1012,3 +1012,5 @@ Video Disk Recorder Revision History - When deleting a recording that is currently still being recorded, the related timer will now automatically be terminated. If this is a repeating timer, it will receive a "First day" setting that skips the timer for this day. +- Fixed closing all unused file descriptors when opening a pipe (thanks to + Werner Fink). diff --git a/thread.c b/thread.c index 7e5b0ea7..4d7fccaf 100644 --- a/thread.c +++ b/thread.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: thread.c 1.16 2001/10/27 13:23:06 kls Exp $ + * $Id: thread.c 1.17 2002/02/17 14:47:28 kls Exp $ */ #include "thread.h" @@ -277,8 +277,11 @@ bool cPipe::Open(const char *Command, const char *Mode) _exit(-1); } else { - for (int i = STDERR_FILENO + 1; i < fd[1 - iopipe]; i++) - close(i); //close all dup'ed filedescriptors + for (int i = 0; i <= fd[1]; i++) { + if (i == STDIN_FILENO || i == STDOUT_FILENO || i == STDERR_FILENO) + continue; + close(i); // close all dup'ed filedescriptors + } if (execl("/bin/sh", "sh", "-c", Command, NULL) == -1) { LOG_ERROR_STR(Command); close(fd[1 - iopipe]); -- cgit v1.2.3