Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (c *Container) ignoreCgroupError(err error) error {
if err == nil {
return nil
}
if errors.Is(err, os.ErrNotExist) && c.runType() == Stopped && !c.cgroupManager.Exists() {
if errors.Is(err, os.ErrNotExist) && !c.hasInit() && !c.cgroupManager.Exists() {
return nil
}
return err
Expand Down Expand Up @@ -1006,34 +1006,31 @@ func (c *Container) refreshState() error {
if paused {
return c.state.transition(&pausedState{c: c})
}
t := c.runType()
switch t {
case Created:
if !c.hasInit() {
return c.state.transition(&stoppedState{c: c})
}
// The presence of exec fifo helps to distinguish between
// the created and the running states.
if _, err := os.Stat(filepath.Join(c.stateDir, execFifoFilename)); err == nil {
return c.state.transition(&createdState{c: c})
case Running:
return c.state.transition(&runningState{c: c})
}
return c.state.transition(&stoppedState{c: c})
return c.state.transition(&runningState{c: c})
}

func (c *Container) runType() Status {
// hasInit tells whether the container init process exists.
func (c *Container) hasInit() bool {
if c.initProcess == nil {
return Stopped
return false
}
pid := c.initProcess.pid()
stat, err := system.Stat(pid)
if err != nil {
return Stopped
return false
}
if stat.StartTime != c.initProcessStartTime || stat.State == system.Zombie || stat.State == system.Dead {
return Stopped
}
// We'll create exec fifo and blocking on it after container is created,
// and delete it after start container.
if _, err := os.Stat(filepath.Join(c.stateDir, execFifoFilename)); err == nil {
return Created
return false
}
return Running
return true
}

func (c *Container) isPaused() (bool, error) {
Expand Down
17 changes: 8 additions & 9 deletions libcontainer/state_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (r *runningState) status() Status {
func (r *runningState) transition(s containerState) error {
switch s.(type) {
case *stoppedState:
if r.c.runType() == Running {
if r.c.hasInit() {
return ErrRunning
}
r.c.state = s
Expand All @@ -118,7 +118,7 @@ func (r *runningState) transition(s containerState) error {
}

func (r *runningState) destroy() error {
if r.c.runType() == Running {
if r.c.hasInit() {
return ErrRunning
}
return destroy(r.c)
Expand Down Expand Up @@ -170,14 +170,13 @@ func (p *pausedState) transition(s containerState) error {
}

func (p *pausedState) destroy() error {
t := p.c.runType()
if t != Running && t != Created {
if err := p.c.cgroupManager.Freeze(configs.Thawed); err != nil {
return err
}
return destroy(p.c)
if p.c.hasInit() {
return ErrPaused
Copy link
Copy Markdown

@ssst0n3 ssst0n3 Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when t == Created, hasInit() returns false:

  • Before this commit: It returns ErrPaused.
  • After this commit: p.c.cgroupManager.Freeze(configs.Thawed) is executed.

}
if err := p.c.cgroupManager.Freeze(configs.Thawed); err != nil {
return err
}
return ErrPaused
return destroy(p.c)
}

// restoredState is the same as the running state but also has associated checkpoint
Expand Down