Skip to contentSkip to conversation

How to close ALSA device nodes?

DISCUSSION Rémi Denis-Courmont 2 participants 2 messages Oct 18, 2009

lore
Share & tools
lore
#0 lore raw

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/[email protected]/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,

Signature · 6 lines
Rémi Denis-Courmont
http://www.remlab.net/
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
#1 lore raw

2009/10/18 Rémi Denis-Courmont <[email protected]>:

Quoted 14 lines

       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/[email protected]/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...

Quoted 5 lines

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..