Skip to content

Commit d5b4a3e

Browse files
Fix race against systemd
- T0: runc triggers a systemd unit creation asynchronously from [here](https://github.com/opencontainers/runc/blob/master/libcontainer/cgroups/systemd/apply_systemd.go#L298) - T1: runc then moves ahead and starts creating cgroup paths(.scope directories), [here](https://github.com/opencontainers/runc/blob/master/libcontainer/cgroups/systemd/apply_systemd.go#L348). Kernel creates .scope directory and cgroup.procs file(along with other default files) in the directory automatically, in an atomic manner. - T3: systemd execution thread which was invoked at time `T0`, is still in the process of unit creation. systemd also trying to create cgroup paths and deletes the `.scope` directory which is created at time `T1` by runc from [here](https://github.com/systemd/systemd/blob/v219/src/shared/cgroup-util.c#L1630) in the code Signed-off-by: vikaschoudhary16 <[email protected]>
1 parent e6516b3 commit d5b4a3e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

libcontainer/cgroups/systemd/apply_systemd.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,13 @@ func (m *Manager) Apply(pid int) error {
295295
}
296296
}
297297

298-
if _, err := theConn.StartTransientUnit(unitName, "replace", properties, nil); err != nil && !isUnitExists(err) {
298+
statusChan := make(chan string)
299+
if _, err := theConn.StartTransientUnit(unitName, "replace", properties, statusChan); err != nil && !isUnitExists(err) {
299300
return err
300301
}
301302

303+
<-statusChan
304+
302305
if err := joinCgroups(c, pid); err != nil {
303306
return err
304307
}

0 commit comments

Comments
 (0)