AUDIODEV should be exported when using pulseaudio

Bug #177072 reported by Sebastian Keller
6
Affects Status Importance Assigned to Milestone
esound (Ubuntu)
Invalid
Wishlist
Martin Pitt

Bug Description

I'm using Ubuntu Hardy and have pulseaudio instead of esd installed.
Many apps (like xchat-gnome) still use the old esd libraries, and so i have to use the compatibility layer.
When starting xchat-gnome it spends lot of time, about a minute, trying to connect to esd - without success.
During that time the program seems frozen.

I took a look at the strace output during that time and i recognized:
access("/tmp/.esd/socket", R_OK|W_OK) = -1 ENOENT (No such file or directory)

It seems like pulseaudio creates the compatibility sockets in places like /tmp/.esd-$UID but does not link them to /tmp/.esd, which seems like a good decission for multi-user environments, so i don't think it would be good to change this behaviour.

But i found another workaround:
If you look at util.c (in the esound sources), you can see, that it composes the dirname to look for the socket of /tmp/.esd and the content of the environment variable $AUDIODEV
So if you set $AUDIODEV to "-$UID" it can find the socket and does not waste one minute trying and failing to connect.

I tried:
AUDIODEV="-$UID" xchat-gnome
and everything went as expected, the program was no longer frozen after starting.

So to make things work for programs still using old esd-libraries in combination with pulseaudio AUDIODEV should be exported in some place it would be set for every program in the users session.

description: updated
Revision history for this message
Sebastian Keller (skeller) wrote :

I created the attached file as /etc/X11/Xsession.d/51pulseaudio-esd (i just chose a number before the 55 of the .gnomerc so it could be easily overwritten by that).
This way AUDIODEV is set on every login through gdm for every user. Should work for kdm, too, but i haven't tested it.
Only programs started with sudo would not have set the correct AUDIODEV-value.

Revision history for this message
Pedro Villavicencio (pedro) wrote :

Thanks for your work, Martin may you take a look to it? thanks you!.

Changed in pulseaudio:
assignee: nobody → pitti
importance: Undecided → Low
status: New → Triaged
Revision history for this message
Sebastian Keller (skeller) wrote :

I just found out that setting AUDIODEV to "-1000" (according to my user-id) results in problems when using sdl with alsa as sound backend. Zsnes for example has no sound, because alsa fails to open the pcm:
ALSA lib pcm.c:2145:(snd_pcm_open_noupdate) Unknown PCM -1000

So defining AUDIODEV session-wide is not a good idea.

Defining it just for programs which would freeze otherwise isn't a good idea either, since there might be some corner cases which nobody has found yet. For example without the workaround gossip works normally, except when you select some date in the log-viewer, then it freezes.

Maybe a patched version of libesd0 can be used. The patched version might only need a changed "esd_get_socket_dirname" in util.c to consider the user-id instead of the AUDIODEV environment-variable. This package could be called libesd0-pulse and provide libesd0 so it can simply replace it and pulseaudio-esound-compat should depend on this specific version of the package.

Revision history for this message
Daniel T Chen (crimsun) wrote :

Patching utils.c seems reasonable to me. Whether there should be a separate "libesd0-pulse" raises issues for 6.06 users, e.g., do we wholescale migrate them to said package? What if they are happily using libesd0-alsa and don't wish to switch?

Changed in pulseaudio:
importance: Low → Wishlist
Revision history for this message
Sebastian Keller (skeller) wrote :

Patching esd_get_socket_dirname in utils.c without #ifdef would also affect the behaviour of the original esound-daemon (if somebody is not using pulse as replacement) as it uses the name from this function for the creation of the socket, too. I'm not sure if this might lead to problems.

The idea behind the extra package was that if they install pulseaudio-esound-compat it could conflict with the -alsa one and require the -pulse one. And if pulse gets included by default in ubuntu-desktop (which currently is the case) -alsa should automatically get removed because of this. The old esound package on the other hand should conflict with the -pulse version of the lib, so the people can install it aswell. However this might be wrong, since I don't know that much about packaging.

I'm also not sure about this being a wishlist bug, since it could be the fix to a bugreport rated medium (#177486), which keeps the default irc-client frozen for about a minute directly after you start it.

Revision history for this message
Sebastien Bacher (seb128) wrote :

Setting an hardy milestone having applications freezing for a minute is not a nice user experience

Changed in esound:
milestone: none → ubuntu-8.04
Revision history for this message
Matti Lindell (mlind) wrote :

Was this pitti's patch dropped by a mistake --> http://people.ubuntu.com/patches/esound.multiuser.diff ? Without it esound doesn't find the socket created by pulseaudio-esound-compat (in /tmp/.esd-$UID/).

Revision history for this message
Sebastian Keller (skeller) wrote :

In this patch, isn't the removal of the "dirname == NULL" check causing a small leak, since the space will be allocated everytime the function is called?

Revision history for this message
Daniel T Chen (crimsun) wrote :

This is fixed with seb's upload of -0ubuntu7.

Changed in esound:
status: Triaged → Invalid
Revision history for this message
Sebastian Keller (skeller) wrote :

Yes, I just tested it seems it was the patch that was dropped by mistake. It works now.

However I'm still not sure if this patch has a small memory leak, because everytime the function is called, memory for dirname is allocated. This is never freed, because in the original function it would only be allocated once, because it is meant to be static. By removing the "if (dirname == NULL)" check it gets allocated in every call of the function. It does not seem to be neccessary to remove this check, as the function itself is not static. So adding the check back would close the leak - however it might be better to hear the patch authors opinion on that.

Revision history for this message
Martin Pitt (pitti) wrote :

Thanks, Sebastian:

esound (0.2.38-0ubuntu8) hardy; urgency=low

  * util.c: Fix memory leak in our patch to support multiple users. Thanks to
    Sebastian Keller for spotting this! (See LP #177072)

 -- Martin Pitt <email address hidden> Fri, 01 Feb 2008 17:57:00 +0100

I also updated http://people.ubuntu.com/patches/esound.multiuser.diff accordingly.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.