implement wait on freeze

Docker-DCO-1.1-Signed-off-by: Victor Vieux <vieux@docker.com> (github: vieux)
This commit is contained in:
Victor Vieux 2014-06-04 00:25:07 +00:00
parent 313ab78d1f
commit ae0b8c7d9d
3 changed files with 33 additions and 1 deletions

View file

@ -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) {