[vdr] [patch] avoid inheritance of file descriptors

Deti Fliegl deti at fliegl.de
Mon Dec 10 15:28:36 CET 2007


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:
--- 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;


Comments, ideas? I would be happy to see this little patch applied to 
1.4 and 1.5 trunks of VDR.

Deti



More information about the vdr mailing list