1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Use container.Lock in public ToDisk method

Here was possible race with inspect where we changing HostConfig.Links
Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com> (github: LK4D4)
This commit is contained in:
LK4D4 2014-07-11 21:49:24 +04:00
parent 9319b7aef1
commit eae5cf1e20

View file

@ -106,7 +106,7 @@ func (container *Container) FromDisk() error {
return container.readHostConfig() return container.readHostConfig()
} }
func (container *Container) ToDisk() error { func (container *Container) toDisk() error {
data, err := json.Marshal(container) data, err := json.Marshal(container)
if err != nil { if err != nil {
return err return err
@ -125,6 +125,13 @@ func (container *Container) ToDisk() error {
return container.WriteHostConfig() return container.WriteHostConfig()
} }
func (container *Container) ToDisk() error {
container.Lock()
err := container.toDisk()
container.Unlock()
return err
}
func (container *Container) readHostConfig() error { func (container *Container) readHostConfig() error {
container.hostConfig = &runconfig.HostConfig{} container.hostConfig = &runconfig.HostConfig{}
// If the hostconfig file does not exist, do not read it. // If the hostconfig file does not exist, do not read it.
@ -482,7 +489,7 @@ func (container *Container) monitor(callback execdriver.StartCallback) error {
// FIXME: here is race condition between two RUN instructions in Dockerfile // FIXME: here is race condition between two RUN instructions in Dockerfile
// because they share same runconfig and change image. Must be fixed // because they share same runconfig and change image. Must be fixed
// in server/buildfile.go // in server/buildfile.go
if err := container.ToDisk(); err != nil { if err := container.toDisk(); err != nil {
utils.Errorf("Error dumping container %s state to disk: %s\n", container.ID, err) utils.Errorf("Error dumping container %s state to disk: %s\n", container.ID, err)
} }
} }
@ -1081,7 +1088,7 @@ func (container *Container) waitForStart() error {
c.Close() c.Close()
} }
} }
if err := container.ToDisk(); err != nil { if err := container.toDisk(); err != nil {
utils.Debugf("%s", err) utils.Debugf("%s", err)
} }
container.State.SetRunning(command.Pid()) container.State.SetRunning(command.Pid())