Skip to content

Commit cb7e304

Browse files
committed
dbus: make New() fall back to direct systemd connection
Previously, New() would attempt to connect to the system-wide DBus. This changes the behaviour so that in the event that such a connection fails, it falls back to attempting a direct connection to the private systemd socket (i.e. via NewSystemdConnection()). A new, more specific `NewSystemConnection()` constructor is introduced which provides the previous behaviour. Fixes: #207
1 parent 61c7ee6 commit cb7e304

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

dbus/dbus.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,19 @@ type Conn struct {
8383
}
8484
}
8585

86-
// New establishes a connection to the system bus and authenticates.
86+
// New establishes a connection to any available bus and authenticates.
8787
// Callers should call Close() when done with the connection.
8888
func New() (*Conn, error) {
89+
conn, err := NewSystemConnection()
90+
if err != nil && os.Geteuid() == 0 {
91+
return NewSystemdConnection()
92+
}
93+
return conn, err
94+
}
95+
96+
// NewSystemConnection establishes a connection to the system bus and authenticates.
97+
// Callers should call Close() when done with the connection
98+
func NewSystemConnection() (*Conn, error) {
8999
return NewConnection(func() (*dbus.Conn, error) {
90100
return dbusAuthHelloConnection(dbus.SystemBusPrivate)
91101
})

0 commit comments

Comments
 (0)