Skip to content

Commit 963cd54

Browse files
committed
Merge pull request #30 from justinsb/extra_properties
Expose the extra type-specific properties on a unit
2 parents 57eb061 + 6809ca4 commit 963cd54

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

dbus/methods.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ func (c *Conn) KillUnit(name string, signal int32) {
137137
c.sysobj.Call("org.freedesktop.systemd1.Manager.KillUnit", 0, name, "all", signal).Store()
138138
}
139139

140-
// GetUnitProperties takes the unit name and returns all of its dbus object properties.
141-
func (c *Conn) GetUnitProperties(unit string) (map[string]interface{}, error) {
140+
// getProperties takes the unit name and returns all of its dbus object properties, for the given dbus interface
141+
func (c *Conn) getProperties(unit string, dbusInterface string) (map[string]interface{}, error) {
142142
var err error
143143
var props map[string]dbus.Variant
144144

@@ -148,7 +148,7 @@ func (c *Conn) GetUnitProperties(unit string) (map[string]interface{}, error) {
148148
}
149149

150150
obj := c.sysconn.Object("org.freedesktop.systemd1", path)
151-
err = obj.Call("org.freedesktop.DBus.Properties.GetAll", 0, "org.freedesktop.systemd1.Unit").Store(&props)
151+
err = obj.Call("org.freedesktop.DBus.Properties.GetAll", 0, dbusInterface).Store(&props)
152152
if err != nil {
153153
return nil, err
154154
}
@@ -161,6 +161,18 @@ func (c *Conn) GetUnitProperties(unit string) (map[string]interface{}, error) {
161161
return out, nil
162162
}
163163

164+
// GetUnitProperties takes the unit name and returns all of its dbus object properties.
165+
func (c *Conn) GetUnitProperties(unit string) (map[string]interface{}, error) {
166+
return c.getProperties(unit, "org.freedesktop.systemd1.Unit")
167+
}
168+
169+
// GetUnitTypeProperties returns the extra properties for a unit, specific to the unit type.
170+
// Valid values for unitType: Service, Socket, Target, Device, Mount, Automount, Snapshot, Timer, Swap, Path, Slice, Scope
171+
// return "dbus.Error: Unknown interface" if the unitType is not the correct type of the unit
172+
func (c *Conn) GetUnitTypeProperties(unit string, unitType string) (map[string]interface{}, error) {
173+
return c.getProperties(unit, "org.freedesktop.systemd1." + unitType)
174+
}
175+
164176
// ListUnits returns an array with all currently loaded units. Note that
165177
// units may be known by multiple names at the same time, and hence there might
166178
// be more unit names loaded than actual units behind them.

0 commit comments

Comments
 (0)