Skip to content

Commit

Permalink
Merge pull request moby#19722 from WeiZhang555/exec-restarting
Browse files Browse the repository at this point in the history
Forbid exec a restarting container
  • Loading branch information
coolljt0725 committed Jan 27, 2016
2 parents 3cf4884 + 1d2208f commit 0ae9430
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions container/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,14 @@ func (s *State) IsPaused() bool {
return res
}

// IsRestarting returns whether the container is restarting or not.
func (s *State) IsRestarting() bool {
s.Lock()
res := s.Restarting
s.Unlock()
return res
}

// SetRemovalInProgress sets the container state as being removed.
func (s *State) SetRemovalInProgress() error {
s.Lock()
Expand Down
6 changes: 6 additions & 0 deletions daemon/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ func (d *Daemon) getExecConfig(name string) (*exec.Config, error) {
if container.IsPaused() {
return nil, derr.ErrorCodeExecPaused.WithArgs(container.ID)
}
if container.IsRestarting() {
return nil, derr.ErrorCodeExecRestarting.WithArgs(container.ID)
}
return ec, nil
}
}
Expand All @@ -76,6 +79,9 @@ func (d *Daemon) getActiveContainer(name string) (*container.Container, error) {
if container.IsPaused() {
return nil, derr.ErrorCodeExecPaused.WithArgs(name)
}
if container.IsRestarting() {
return nil, derr.ErrorCodeExecRestarting.WithArgs(name)
}
return container, nil
}

Expand Down
9 changes: 9 additions & 0 deletions errors/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,15 @@ var (
HTTPStatusCode: http.StatusConflict,
})

// ErrorCodeExecRestarting is generated when we try to start an exec
// but the container is restarting.
ErrorCodeExecRestarting = errcode.Register(errGroup, errcode.ErrorDescriptor{
Value: "EXECRESTARTING",
Message: "Container %s is restarting, wait until the container is running",
Description: "An attempt to start an 'exec' was made, but the owning container is restarting",
HTTPStatusCode: http.StatusConflict,
})

// ErrorCodeExecRunning is generated when we try to start an exec
// but its already running.
ErrorCodeExecRunning = errcode.Register(errGroup, errcode.ErrorDescriptor{
Expand Down

0 comments on commit 0ae9430

Please sign in to comment.