From b29924d062584a9006195a88180cdd88285e84a3 Mon Sep 17 00:00:00 2001 From: Dongsu Park Date: Thu, 14 Jul 2016 13:52:42 +0200 Subject: [PATCH] systemd: get dbus connection directly in NewSystemdUnitManager Let's get dbus connection directly inside NewSystemdUnitManager, instead of calling a separate function createDbusConnection(). Suggested by @jonboulle. See https://github.com/coreos/fleet/pull/1393#discussion_r70782867 --- systemd/manager.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/systemd/manager.go b/systemd/manager.go index 4c8aa1561..d71eb4d4a 100644 --- a/systemd/manager.go +++ b/systemd/manager.go @@ -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 } @@ -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 {