@@ -167,6 +167,28 @@ func (c *Conn) GetUnitProperties(unit string) (map[string]interface{}, error) {
167167 return c .getProperties (unit , "org.freedesktop.systemd1.Unit" )
168168}
169169
170+ func (c * Conn ) getProperty (unit string , dbusInterface string , propertyName string ) (* Property , error ) {
171+ var err error
172+ var prop dbus.Variant
173+
174+ path := ObjectPath ("/org/freedesktop/systemd1/unit/" + unit )
175+ if ! path .IsValid () {
176+ return nil , errors .New ("invalid unit name: " + unit )
177+ }
178+
179+ obj := c .sysconn .Object ("org.freedesktop.systemd1" , path )
180+ err = obj .Call ("org.freedesktop.DBus.Properties.Get" , 0 , dbusInterface , propertyName ).Store (& prop )
181+ if err != nil {
182+ return nil , err
183+ }
184+
185+ return & Property {Name : propertyName , Value : prop }, nil
186+ }
187+
188+ func (c * Conn ) GetUnitProperty (unit string , propertyName string ) (* Property , error ) {
189+ return c .getProperty (unit , "org.freedesktop.systemd1.Unit" , propertyName )
190+ }
191+
170192// GetUnitTypeProperties returns the extra properties for a unit, specific to the unit type.
171193// Valid values for unitType: Service, Socket, Target, Device, Mount, Automount, Snapshot, Timer, Swap, Path, Slice, Scope
172194// return "dbus.Error: Unknown interface" if the unitType is not the correct type of the unit
@@ -185,6 +207,10 @@ func (c *Conn) SetUnitProperties(name string, runtime bool, properties ...Proper
185207 return c .sysobj .Call ("SetUnitProperties" , 0 , name , runtime , properties ).Store ()
186208}
187209
210+ func (c * Conn ) GetUnitTypeProperty (unit string , unitType string , propertyName string ) (* Property , error ) {
211+ return c .getProperty (unit , "org.freedesktop.systemd1." + unitType , propertyName )
212+ }
213+
188214// ListUnits returns an array with all currently loaded units. Note that
189215// units may be known by multiple names at the same time, and hence there might
190216// be more unit names loaded than actual units behind them.
0 commit comments