Skip to content

Commit

Permalink
systemd: get dbus connection directly in NewSystemdUnitManager
Browse files Browse the repository at this point in the history
Let's get dbus connection directly inside NewSystemdUnitManager,
instead of calling a separate function createDbusConnection().

Suggested by @jonboulle.
See coreos#1393 (comment)
  • Loading branch information
Dongsu Park committed Jul 14, 2016
1 parent 26f9bef commit b29924d
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions systemd/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ type systemdUnitManager struct {
}

func NewSystemdUnitManager(uDir string, systemdUser bool) (*systemdUnitManager, error) {
systemd, err := createDbusConnection(systemdUser)
var systemd *dbus.Conn
var err error
if systemdUser {
systemd, err = dbus.NewUserConnection()
} else {
systemd, err = dbus.New()
}
if err != nil {
return nil, err
}
Expand All @@ -60,13 +66,6 @@ func NewSystemdUnitManager(uDir string, systemdUser bool) (*systemdUnitManager,
return &mgr, nil
}

func createDbusConnection(systemdUser bool) (*dbus.Conn, error) {
if systemdUser {
return dbus.NewUserConnection()
}
return dbus.New()
}

func hashUnitFiles(dir string) (map[string]unit.Hash, error) {
uNames, err := lsUnitsDir(dir)
if err != nil {
Expand Down

0 comments on commit b29924d

Please sign in to comment.