diff --git a/libcontainer/cgroups/fs/apply_raw.go b/libcontainer/cgroups/fs/apply_raw.go index 8fa2599..2231ab9 100644 --- a/libcontainer/cgroups/fs/apply_raw.go +++ b/libcontainer/cgroups/fs/apply_raw.go @@ -164,6 +164,11 @@ func writeFile(dir, file, data string) error { return ioutil.WriteFile(filepath.Join(dir, file), []byte(data), 0700) } +func readFile(dir, file string) (string, error) { + data, err := ioutil.ReadFile(filepath.Join(dir, file)) + return string(data), err +} + func removePath(p string, err error) error { if err != nil { return err diff --git a/libcontainer/cgroups/fs/freezer.go b/libcontainer/cgroups/fs/freezer.go index 432018f..5c9ba5b 100644 --- a/libcontainer/cgroups/fs/freezer.go +++ b/libcontainer/cgroups/fs/freezer.go @@ -4,6 +4,7 @@ import ( "io/ioutil" "path/filepath" "strings" + "time" "github.com/dotcloud/docker/pkg/libcontainer/cgroups" ) @@ -22,6 +23,17 @@ func (s *freezerGroup) Set(d *data) error { if err := writeFile(dir, "freezer.state", string(d.c.Freezer)); err != nil { return err } + + for { + state, err := readFile(dir, "freezer.state") + if err != nil { + return err + } + if strings.TrimSpace(state) == string(d.c.Freezer) { + break + } + time.Sleep(1 * time.Millisecond) + } default: if _, err := d.join("freezer"); err != nil && err != cgroups.ErrNotFound { return err diff --git a/libcontainer/cgroups/systemd/apply_systemd.go b/libcontainer/cgroups/systemd/apply_systemd.go index eb1425b..c486dbe 100644 --- a/libcontainer/cgroups/systemd/apply_systemd.go +++ b/libcontainer/cgroups/systemd/apply_systemd.go @@ -3,6 +3,7 @@ package systemd import ( + "bytes" "fmt" "io/ioutil" "os" @@ -10,6 +11,7 @@ import ( "strconv" "strings" "sync" + "time" systemd1 "github.com/coreos/go-systemd/dbus" "github.com/dotcloud/docker/pkg/libcontainer/cgroups" @@ -351,7 +353,20 @@ func Freeze(c *cgroups.Cgroup, state cgroups.FreezerState) error { return err } - return ioutil.WriteFile(filepath.Join(path, "freezer.state"), []byte(state), 0) + if err := ioutil.WriteFile(filepath.Join(path, "freezer.state"), []byte(state), 0); err != nil { + return err + } + for { + state_, err := ioutil.ReadFile(filepath.Join(path, "freezer.state")) + if err != nil { + return err + } + if string(state) == string(bytes.TrimSpace(state_)) { + break + } + time.Sleep(1 * time.Millisecond) + } + return nil } func GetPids(c *cgroups.Cgroup) ([]int, error) {