Skip to content

Commit d659fb6

Browse files
authored
Merge pull request #208 from squeed/use-systemd-socket
dbus: make New() fall back to direct systemd connection
2 parents 64d5cd7 + cb7e304 commit d659fb6

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)