[alsa-devel] How to close ALSA device nodes?
Hello,
I'm getting a bug report against VLC media player whereby ALSA sound output stops working when the screensaver is inhibited. It turns out that VLC is leaking any file descriptor open through ALSA-lib into child processes. The exact same issue was already raised by mplayer... 6 years ago: http://www.mail-archive.com/alsa-devel@lists.sourceforge.net/msg06249.html
In other cases (V4L, OSS, DVB, DVD, sockets, even regular files...), VLC would open the device nodes with O_CLOEXEC flag (if supported by kernel and libc) and fallback to setting FD_CLOEXEC via fcntl(). Then the descriptor is automatically, and in the earlier case, thread-safely, closed whenever VLC - forks and- execs. With ALSA-lib, I cannot figure any way to achieve that...
From the earlier thread, I reckon that ALSA developers consider that this is an upper-layer issue. Maybe so, but then how is the upper-layer supposed to find which file descriptors ALSA-lib has opened - if any? Conversely, if ALSA- lib won't tell while file descriptors it is using, what could possibly be the use case for not closing those on exec?
Best regards,
2009/10/18 Rémi Denis-Courmont rem@videolan.org:
Hello,
I'm getting a bug report against VLC media player whereby ALSA sound output stops working when the screensaver is inhibited. It turns out that VLC is leaking any file descriptor open through ALSA-lib into child processes. The exact same issue was already raised by mplayer... 6 years ago: http://www.mail-archive.com/alsa-devel@lists.sourceforge.net/msg06249.html
In other cases (V4L, OSS, DVB, DVD, sockets, even regular files...), VLC would open the device nodes with O_CLOEXEC flag (if supported by kernel and libc) and fallback to setting FD_CLOEXEC via fcntl(). Then the descriptor is automatically, and in the earlier case, thread-safely, closed whenever VLC - forks and- execs. With ALSA-lib, I cannot figure any way to achieve that...
From the earlier thread, I reckon that ALSA developers consider that this is an upper-layer issue. Maybe so, but then how is the upper-layer supposed to find which file descriptors ALSA-lib has opened - if any? Conversely, if ALSA- lib won't tell while file descriptors it is using, what could possibly be the use case for not closing those on exec?
I agree that it's a difficult problem for an app that wants to fork and exec another process.. I'd think really should be some way for an app to control the CLOEXEC flag for the file descriptors that alsa-lib has open..
I guess the alternative would be to shutdown all open PCMs, etc. in ALSA in the child process after forking and before the exec, so that they don't end up still open for the new process..
participants (2)
-
Robert Hancock
-
Rémi Denis-Courmont