[pulseaudio-discuss] [RFC PATCH] inotify-wrapper: Quit daemon if pid file is removed

David Henningsson david.henningsson at canonical.com
Mon Jun 3 02:21:57 PDT 2013

On 06/03/2013 10:50 AM, Tanu Kaskinen wrote:
> On Fri, 2013-04-19 at 08:37 +0200, David Henningsson wrote:
>> On 04/17/2013 05:56 PM, David Henningsson wrote:
>>> XDG_RUNTIME_DIR is deleted on logout (according to xdg spec), and
>>> that's where we keep our pid file and native protocol socket.
>>> When these two files are deleted, it makes no sense to run anymore,
>>> so quit. Hanging around is not only sloppy, but can also be harmful:
>>> e g, if esd compat module is loaded, it will bind to the esd address.
>>> When a new pulseaudio process is created on next login of the same
>>> user, pulseaudio cannot start because the esd address is occupied.
> I'll start by clarifying one thing: "session" means here the time when a
> user is logged in in one way or another. There may actually be multiple
> overlapping login sessions, but when talking about XDG_RUNTIME_DIR, one
> "session" may cover multiple login sessions.
> To avoid races, I think things should work like this:
> 1. A new session is created.
> 2. PulseAudio starts and "joins" the session somehow (maybe configured
> to be a part of the session, or maybe started manually - both ways
> should work).
> 3. Session shut-down is initiated.
> 4. PulseAudio quits.
> 5. The system removes the runtime directory after all session daemons
> have exited, or after a timeout if the daemons don't exit quickly
> enough.
> Removing the runtime directory while it's still being used sounds like a
> bad idea. Also, if the session doesn't wait for the daemons to exit
> before ending, the daemons may still be running (perhaps in process of
> shutting down) when the next session starts. That doesn't sound good
> either.
> So, to me it sounds like the session manager is currently broken, and
> your patch works around that brokenness. Therefore, I don't think your
> patch should be included, unless the session manager developers say that
> the session manager is not broken and will not get fixed and the only
> way to know about the session shut-down is to monitor the runtime
> directory existence.
> We already have ConsoleKit and systemd-logind integration. I would have
> imagined that they are sufficient, but I guess those have two problems:
> 1) when the session ends, PulseAudio will wait 20 seconds before
> exiting, and 2) the session manager doesn't wait for PulseAudio to exit.
> If our ConsoleKit/logind modules are the way to manage the lifetime of
> the daemon, I guess we could and should fix at least the 20 second
> delay.

Okay, I'll keep it as a distro patch for now.

I don't really know why we have this 20 second delay (set by 
exit-idle-time). It's one of these things that I feel that if we just 
removed it we'd probably break something though...

The race is probably not too much to worry about at this point, and if 
so, it should probably be fixed on the session manager daemon side 
anyway. But, PulseAudio is usually started by autospawning (at least on 
Ubuntu), so maybe the session manager does not feel too responsible for 
shutting it down, if it wasn't the one starting it.

David Henningsson, Canonical Ltd.

More information about the pulseaudio-discuss mailing list