From 6ecb469b2b9845c9559e541be2f4614b23e7a85d Mon Sep 17 00:00:00 2001 From: Qiang Huang Date: Tue, 2 Aug 2016 15:43:04 +0800 Subject: [PATCH] Fix race condition when using cgroups.Paths Signed-off-by: Qiang Huang --- libcontainer/cgroups/fs/apply_raw.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libcontainer/cgroups/fs/apply_raw.go b/libcontainer/cgroups/fs/apply_raw.go index ed46561a..414f0bfd 100644 --- a/libcontainer/cgroups/fs/apply_raw.go +++ b/libcontainer/cgroups/fs/apply_raw.go @@ -104,6 +104,8 @@ func (m *Manager) Apply(pid int) (err error) { if m.Cgroups == nil { return nil } + m.mu.Lock() + defer m.mu.Unlock() var c = m.Cgroups @@ -128,8 +130,6 @@ func (m *Manager) Apply(pid int) (err error) { return cgroups.EnterPid(m.Paths, pid) } - m.mu.Lock() - defer m.mu.Unlock() paths := make(map[string]string) for _, sys := range subsystems { if err := sys.Apply(d); err != nil {