Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions dbus/dbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,30 @@ type Conn struct {
func New() (*Conn, error) {
c := new(Conn)

if err := c.initConnection(); err != nil {
if err := c.initConnection(dbus.SystemBusPrivate); err != nil {
return nil, err
}

c.initJobs()
return c, nil
}

func (c *Conn) initConnection() error {
// NewUserConnection() establishes a connection to the session bus and
// authenticates. This can be used to connect to systemd user instances.
func NewUserConnection() (*Conn, error) {
c := new(Conn)

if err := c.initConnection(dbus.SessionBusPrivate); err != nil {
return nil, err
}

c.initJobs()
return c, nil
}

func (c *Conn) initConnection(createBus func()(*dbus.Conn, error)) error {
var err error
c.sysconn, err = dbus.SystemBusPrivate()
c.sysconn, err = createBus()
if err != nil {
return err
}
Expand Down