From d57ad7af3d077934426ef0ceab28ca18819a8bab Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Tue, 20 Jun 2017 13:05:40 +0200 Subject: [PATCH] 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. Signed-off-by: Alexander Larsson --- utils/utils.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/utils/utils.go b/utils/utils.go index 8494c02a..613020ed 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -69,8 +69,16 @@ 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) - return err + 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 {