RunUnderSystemdScope: Wait until scope is started before we return
We need to do this, because otherwise we will continue and exit the
pid before systemd has a chance to look at it.
@@ -69,10 +69,18 @@ func RunUnderSystemdScope(pid int, slice string, unitName string) error {
properties = append(properties, newProp("PIDs", []uint32{uint32(pid)}))
properties = append(properties, newProp("Delegate", true))
properties = append(properties, newProp("DefaultDependencies", false))
- _, err = conn.StartTransientUnit(unitName, "replace", properties, nil)
+ ch := make(chan string)
+ _, err = conn.StartTransientUnit(unitName, "replace", properties, ch)
+ if err != nil {
return err
}
+ // Block until job is started
+ <-ch
+
+ return nil
+}
+
func newProp(name string, units interface{}) systemdDbus.Property {
return systemdDbus.Property{
Name: name,
