From f26674696e4cdacffcb3675caa5164cec4a02e67 Mon Sep 17 00:00:00 2001
From: Manuel Amador (Rudd-O) <rudd-o@rudd-o.com>
Date: Mon, 13 Jul 2009 20:06:58 -0500
Subject: [PATCH 2/2] Skip starting PulseAudio session daemon at session logon if a pulseaudio server has been started in system-wide mode, or a specific pulseaudio server has been set as system-wide policy by the system administrator.

---
 src/daemon/start-pulseaudio-x11.in |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/src/daemon/start-pulseaudio-x11.in b/src/daemon/start-pulseaudio-x11.in
index c57c489..eab6fe7 100755
--- a/src/daemon/start-pulseaudio-x11.in
+++ b/src/daemon/start-pulseaudio-x11.in
@@ -19,8 +19,32 @@
 
 set -e
 
+# Skip starting the server if a client endpoint variable has been set for this session.
 [ -z "$PULSE_SERVER" ]
 
+# Skip starting the server if a server is running in system-wide mode.
+# Otherwise this user's session server will catfight the system-wide server.
+# This covers the scenario of terminal servers with system-wide sound
+# servers and the scenario of people willing to sacrifice some security
+# and functionality for a system-wide server that lets them listen to apps ike
+# MPD or text-to-speech notifications in the console, in parallel with
+# graphical desktop applications.
+[ -f "@PA_SYSTEM_RUNTIME_PATH@/pid" ] && exit 0
+
+# Exit if the user has no client.conf and the system client.conf sets a default server.
+# This covers the scenario of terminal servers and machines that exclusively
+# use a remote audio server (say, connected to a stereo) in a fixed
+# configuration.
+# If, however, the user has a client.conf, we continue to server start
+# because we assume the user knows what he is doing, has overridden
+# default system policy, and wants a local server to be started anyway.
+# This exception is in compliance with observations in bug 606.
+if [ ! -f ~/.pulse/client.conf ] ; then
+	if [ -x /bin/grep -a -f "@PA_DEFAULT_CONFIG_DIR@/client.conf" ] ; then
+		/bin/grep -q "^ *default-server *=" "@PA_DEFAULT_CONFIG_DIR@/client.conf" && exit 0
+	fi
+fi
+
 @PA_BINARY@ --start "$@"
 
 if [ x"$DISPLAY" != x ] ; then
-- 
1.6.2.5

