From patchwork Mon Dec 10 14:28:36 2007 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deti Fliegl X-Patchwork-Id: 12554 Received: from mailout1-test.lrz-muenchen.de ([129.187.254.156] helo=lxmhs29.lrz-muenchen.de) by www.linuxtv.org with esmtp (Exim 4.63) (envelope-from ) id 1J1jcd-0008Qq-Pl for vdr@linuxtv.org; Mon, 10 Dec 2007 15:28:39 +0100 Received: from [IPv6:2001:4ca0:2001:10:204:75ff:fee6:181a] (redbreast.net.informatik.tu-muenchen.de [IPv6:2001:4ca0:2001:10:204:75ff:fee6:181a]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lxmhs29.lrz-muenchen.de (Postfix) with ESMTP id 071B07000081 for ; Mon, 10 Dec 2007 15:28:37 +0100 (CET) Message-ID: <475D4D14.40609@fliegl.de> Date: Mon, 10 Dec 2007 15:28:36 +0100 From: Deti Fliegl User-Agent: Thunderbird 2.0.0.6 (X11/20071022) MIME-Version: 1.0 To: VDR Mailing List Subject: [vdr] [patch] avoid inheritance of file descriptors X-BeenThere: vdr@linuxtv.org X-Mailman-Version: 2.1.9 Precedence: list Reply-To: VDR Mailing List List-Id: VDR Mailing List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Dec 2007 14:28:39 -0000 Status: O X-Status: X-Keywords: X-UID: 14812 Hi, I think there is a problem in calling external programs from plugins. If such a program takes some while for execution (even in background) it gets inherited all file descriptors of VDR. This prevents vdr from zapping to another channel or even from restarting properly. You will see messages like: ERROR: /dev/dvb/adapter0/dvr0: Device or resource busy or ERROR (svdrp.c,84): Address already in use Reason: By default unix inherits all file descriptors to child processes when calling exec*(...) or system(...). You can avoid this by setting FD_CLOEXEC on all file descriptors that should not be inherited. Patch: Comments, ideas? I would be happy to see this little patch applied to 1.4 and 1.5 trunks of VDR. Deti --- dvbdevice.c~ 2007-12-10 15:19:51.116943936 +0100 +++ dvbdevice.c 2007-12-10 15:19:51.120944682 +0100 @@ -63,6 +63,7 @@ int fd = open(FileName, Mode); if (fd < 0 && ReportError) LOG_ERROR_STR(FileName); + fcntl(fd, F_SETFD, FD_CLOEXEC); return fd; } --- svdrp.c~ 2007-12-10 15:20:12.476929058 +0100 +++ svdrp.c 2007-12-10 15:20:12.480929804 +0100 @@ -91,7 +91,7 @@ LOG_ERROR; return false; } - oldflags |= O_NONBLOCK; + oldflags |= O_NONBLOCK|FD_CLOEXEC; if (fcntl(sock, F_SETFL, oldflags) < 0) { LOG_ERROR; return false;