Skip to content

Commit

Permalink
engine: resources: mount: Fix the dbus call for reloading systemd
Browse files Browse the repository at this point in the history
The Reload method cannot just be invoked on the administrative DBus
object. Just like the method for reloading specific units, it needs
to be invoked on the proper DBus service, addressing the proper object
and using the right interface.

Added an additional constant for the systemd DBus service. Even though
it shares the same value as the interface base name, this is
happenstance and it's technically incorrect to open a connection to an
interface name. The connection needs a service name.

Fixes purpleidea#509
  • Loading branch information
ffrank committed Jun 4, 2019
1 parent a235b76 commit 191a249
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions engine/resources/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ const (
// diskByLabel is the location of symlinks for partitions by label.
diskByPartLabel = devDisk + "by-partlabel/"

// dbusSystemdService is the service to connect to systemd itself.
dbusSystemd1Service = "org.freedesktop.systemd1"
// dbusSystemd1Interface is the base systemd1 path.
dbusSystemd1Path = "/org/freedesktop/systemd1"
// dbusUnitPath is the dbus path where mount unit files are found.
Expand All @@ -88,6 +90,9 @@ const (
dbusManagerInterface = dbusSystemd1Interface + ".Manager"
// dbusRestartUnit is the dbus method for restarting systemd units.
dbusRestartUnit = dbusManagerInterface + ".RestartUnit"
// dbusReloadSystemd is the dbus method for reloading systemd settings.
// (i.e. systemctl daemon-reload)
dbusReloadSystemd = dbusManagerInterface + ".Reload"
// restartTimeout is the delay before restartUnit is assumed to have
// failed.
dbusRestartCtxTimeout = 10
Expand Down Expand Up @@ -576,7 +581,10 @@ func mountReload() error {
}
defer conn.Close()
// systemctl daemon-reload
conn.BusObject().Call("Reload", 0)
call := conn.Object(dbusSystemd1Service, dbusSystemd1Path).Call(dbusReloadSystemd, 0)
if call.Err != nil {
return errwrap.Wrapf(call.Err, "error reloading systemd")
}

// systemctl restart local-fs.target
if err := restartUnit(conn, "local-fs.target"); err != nil {
Expand Down Expand Up @@ -619,7 +627,7 @@ func restartUnit(conn *dbus.Conn, unit string) error {
defer conn.RemoveSignal(ch)

// restart the unit
sd1 := conn.Object(dbusSystemd1Interface, dbus.ObjectPath(dbusSystemd1Path))
sd1 := conn.Object(dbusSystemd1Service, dbus.ObjectPath(dbusSystemd1Path))
if call := sd1.Call(dbusRestartUnit, 0, unit, "fail"); call.Err != nil {
return errwrap.Wrapf(call.Err, "error restarting unit: %s", unit)
}
Expand Down

0 comments on commit 191a249

Please sign in to comment.