Merge pull request #62 from jsouthworth/fix/only-one-instance
Only launch one D-Bus instance
diff --git a/conn.go b/conn.go
index f7e471d..9aa2e12 100644
--- a/conn.go
+++ b/conn.go
@@ -16,6 +16,7 @@
systemBusLck sync.Mutex
sessionBus *Conn
sessionBusLck sync.Mutex
+ sessionEnvLck sync.Mutex
)
// ErrClosed is the error returned by calls on a closed connection.
@@ -91,6 +92,8 @@
// SessionBusPrivate returns a new private connection to the session bus.
func SessionBusPrivate() (*Conn, error) {
+ sessionEnvLck.Lock()
+ defer sessionEnvLck.Unlock()
address := os.Getenv("DBUS_SESSION_BUS_ADDRESS")
if address != "" && address != "autolaunch:" {
return Dial(address)
diff --git a/conn_other.go b/conn_other.go
index f74b875..289e8c5 100644
--- a/conn_other.go
+++ b/conn_other.go
@@ -5,6 +5,7 @@
import (
"bytes"
"errors"
+ "os"
"os/exec"
)
@@ -23,5 +24,8 @@
return nil, errors.New("dbus: couldn't determine address of session bus")
}
- return Dial(string(b[i+1 : j]))
+ env, addr := string(b[0:i]), string(b[i+1:j])
+ os.Setenv(env, addr)
+
+ return Dial(addr)
}