[mythtv] open file handles and exec()

Geoffrey Hausheer ou401cru02 at sneakemail.com
Sun Jul 13 20:34:59 EDT 2003

I have run into an annoying feature of exec().  When an exec happens, all
open filehandles remain open in the new process unless
'fcntl(fh,F_SETFD,FD_CLOEXEC);' has been done previously.  I've found
that this can cause issues for transcoding, as occasionally the
transcoder is started holding /dev/dsp, which causes mythbackend to be
unable to aquire it, and leads to a no-audio recording.  My current fix
is to add the above fcntl call after every open() of audiodevice, which
does indeed seem to fix the problem, however, it will also be hard to
maintain in the future.  I have seen crude hacks like:
   for (int i = 3; i < 9999; i++)

but that is just plain nasty.

The only other thoughts I've had are to alias open to open/fcntl (once
again nasty), or to create a new open_foo() which does a regular open
followed by the fcntl (nearly as hard to maintain as just adding the
fcntl call).

Ideally I'd like to just be able to launch a new process (the transcoder)
which doesn't inherit any of the parent's file descriptors, but I don't
see a way to do that at the moment.

Any ideas?

  Geoffrey Hausheer

More information about the mythtv-dev mailing list