alsa-lib leaves sound device open for child processes
The alsa-lib doesn't set the close-on-exec flag on its PCM device FD's. The consequence is that processes spawned by alsa-lib clients inherit an open file handle to the PCM device and thereby block it.
For example, mplayer can disable and re-launch the xscreensaver daemon. In the alsa-enabled version of mplayer, the xscreensaver process inherits a pcm handle, although xss can't make use of it. This effectively forces me to restart xss manually after each mplayer session.
Suggested fix:
pcm/pcm_hw.c renamed from pcm/pcm_hw.c.orig +5 -0
@@ -867,6 +867,11 @@ ret = -errno; goto _err; } +if (fcntl ( fd,F_SETFD ,FD_CLOEXEC ) !=0 ) { +SYSERR ("fcntl FD_CLOEXEC failed" ); + ret = -errno; + goto _err; + }if (ioctl (fd,SNDRV_PCM_IOCTL_PVERSION , &ver) <0 ) {SYSERR ("SNDRV_PCM_IOCTL_PVERSION failed" ); ret = -errno;
Signature · 2 lines
Best Regards, | Hi! I'm a .signature virus. Copy me into Sebastian | your ~/.signature to help me spread!
Quoted 16 lines · Sebastian Kapfer
The alsa-lib doesn't set the close-on-exec flag on its PCM device FD's. The consequence is that processes spawned by alsa-lib clients inherit an open file handle to the PCM device and thereby block it.
For example, mplayer can disable and re-launch the xscreensaver daemon. In the alsa-enabled version of mplayer, the xscreensaver process inherits a pcm handle, although xss can't make use of it. This effectively forces me to restart xss manually after each mplayer session.
Suggested fix:
pcm/pcm_hw.c renamed from pcm/pcm_hw.c.orig +0
-0@@ -867,6 +867,11 @@ ret = -errno;
pcm/pcm_hw.c line 877
Quoted 10 lines
pcm/pcm_hw.c renamed from pcm/pcm_hw.c.orig +5
-0goto _err; } +if (fcntl ( fd,F_SETFD ,FD_CLOEXEC ) !=0 ) { +SYSERR ("fcntl FD_CLOEXEC failed" ); + ret = -errno; + goto _err; + }if (ioctl (fd,SNDRV_PCM_IOCTL_PVERSION , &ver) <0 ) {SYSERR ("SNDRV_PCM_IOCTL_PVERSION failed" ); ret = -errno;
Well, I and Abramo think that it's better to force application developers to clean allocated things before they'll call exec(). I believe that not only ALSA file descriptors are open after exec() in mplayer.
Jaroslav
-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
At Wed, 5 Feb 2003 12:20:23 +0100 (CET),
Quoted 3 lines · Jaroslav
Well, I and Abramo think that it's better to force application developers to clean allocated things before they'll call
exec().
the problem is not only the explicit exec() call.
without this bit, you'll pass the fds to other processes even by popen() or system() or whatever. that is, if your application calls an external program in the middle, it can block the operation.
i don't see any critical drawback of setting FD_CLOEXEC as default. the application which needs to pass the alsa-lib's fds _explicitly_ can reset the bit via fcntl() again before calling exec().
Takashi
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
Quoted 6 lines · Takashi Iwai
At Wed, 5 Feb 2003 12:20:23 +0100 (CET),
Quoted 3 lines · Jaroslav
Well, I and Abramo think that it's better to force application developers to clean allocated things before they'll call
exec().
Quoted 8 lines
the problem is not only the explicit
exec()call.
without this bit, you'll pass the fds to other processes even bypopen()orsystem()or whatever. that is, if your application calls an external program in the middle, it can block the operation.i don't see any critical drawback of setting
FD_CLOEXECas default. the application which needs to pass the alsa-lib's fds _explicitly_ can reset the bit viafcntl()again before callingexec().
Do we have any precedence? sockets? fopen? etc.?
Jaroslav
-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
At Wed, 5 Feb 2003 14:05:36 +0100 (CET),
Quoted 14 lines · Jaroslav
Quoted 11 lines · Takashi Iwai
At Wed, 5 Feb 2003 12:20:23 +0100 (CET),
Quoted 3 lines · Jaroslav
Well, I and Abramo think that it's better to force application developers to clean allocated things before they'll call
exec().the problem is not only the explicit
exec()call.
without this bit, you'll pass the fds to other processes even bypopen()orsystem()or whatever. that is, if your application calls an external program in the middle, it can block the operation.
Quoted 5 lines
Quoted 3 lines
i don't see any critical drawback of setting
FD_CLOEXECas default. the application which needs to pass the alsa-lib's fds _explicitly_ can reset the bit viafcntl()again before callingexec().Do we have any precedence? sockets? fopen? etc.?
it has nothing to do with what type of file descriptor is used, or for what purpose.
i meant simply which behavior is _safer_.
sure, we can leave it as it was, and let users debug all. IMO, however, the FD_CLOEXEC would lead to less bugs, if you think which possibility is higher, whether to pass the fd intentionally, or not,
Takashi
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
Speaking as a userspace developer, I expect file descriptors to be inherited by child processes unless I explicitly request otherwise. Yes, I usually make sure that I *DO* request otherwise, but that's not the point...
Cheers,
Chris
--- Takashi Iwai <[email protected]> wrote: > At Wed, 5
Feb 2003 14:05:36 +0100 (CET),
Quoted 44 lines
Quoted 7 lines · Jaroslav
Quoted 4 lines · Takashi Iwai
At Wed, 5 Feb 2003 12:20:23 +0100 (CET),
Quoted 2 lines · Jaroslav
Well, I and Abramo think that it's better to
force application developers
Quoted 1 line
Quoted 1 line
Quoted 1 line
to clean allocated things before they'll call
exec().Quoted 2 lines
Quoted 2 lines
the problem is not only the explicit
exec()call.
Quoted 1 line
Quoted 1 line
without this bit, you'll pass the fds to other
processes even by
Quoted 1 line
Quoted 1 line
popen()orsystem()or whatever. that is, ifyour application calls
Quoted 1 line
Quoted 1 line
an external program in the middle, it can block
the operation.
Quoted 2 lines
Quoted 2 lines
i don't see any critical drawback of setting
FD_CLOEXECas default.Quoted 1 line
Quoted 1 line
the application which needs to pass the
alsa-lib's fds _explicitly_
Quoted 1 line
Quoted 1 line
can reset the bit via
fcntl()again beforecalling
exec().Quoted 2 lines
Do we have any precedence? sockets? fopen? etc.?
it has nothing to do with what type of file descriptor is used, or
for what purpose.i meant simply which behavior is _safer_. sure, we can leave it as it was, and let users debug all.
IMO, however, theFD_CLOEXECwould lead to less bugs, if you think
which possibility is higher, whether to pass the fd intentionally,
or not,
Quoted 4 lines
Takashi
-------------------------------------------------------
Quoted 8 lines
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
Alsa-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel
__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page from News and Sport to Email and Music Charts
http://uk.my.yahoo.com
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
Quoted 5 lines
Speaking as a userspace developer, I expect file descriptors to be inherited by child processes unless I explicitly request otherwise. Yes, I usually make sure that I *DO* request otherwise, but that's not the point...
the question is not about inheritance by child processes. its about close-on-exec behaviour. nobody is proposing any change to the situation after a simple fork(2).
--p
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com