Skip to content

Commit 0d52c1e

Browse files
committed
Merge pull request #60 from ghedo/master
dbus: add support for systemd user instances
2 parents 97e243d + 72deb9f commit 0d52c1e

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

dbus/dbus.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,30 @@ type Conn struct {
8484
func New() (*Conn, error) {
8585
c := new(Conn)
8686

87-
if err := c.initConnection(); err != nil {
87+
if err := c.initConnection(dbus.SystemBusPrivate); err != nil {
8888
return nil, err
8989
}
9090

9191
c.initJobs()
9292
return c, nil
9393
}
9494

95-
func (c *Conn) initConnection() error {
95+
// NewUserConnection() establishes a connection to the session bus and
96+
// authenticates. This can be used to connect to systemd user instances.
97+
func NewUserConnection() (*Conn, error) {
98+
c := new(Conn)
99+
100+
if err := c.initConnection(dbus.SessionBusPrivate); err != nil {
101+
return nil, err
102+
}
103+
104+
c.initJobs()
105+
return c, nil
106+
}
107+
108+
func (c *Conn) initConnection(createBus func()(*dbus.Conn, error)) error {
96109
var err error
97-
c.sysconn, err = dbus.SystemBusPrivate()
110+
c.sysconn, err = createBus()
98111
if err != nil {
99112
return err
100113
}

0 commit comments

Comments
 (0)