Skip to content

Commit 10c951e

Browse files
committed
add ErrCgroupNotExist
For some rootless container, runc has no access to cgroup, But the container is still running. So we should return the `ErrNotRunning` and `ErrCgroupNotExist` error seperatlly. Signed-off-by: lifubang <[email protected]>
1 parent 1590491 commit 10c951e

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

libcontainer/container_linux.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,11 @@ func (c *Container) Signal(s os.Signal) error {
394394
// https://github.com/opencontainers/runc/pull/4395#pullrequestreview-2291179652
395395
return c.signal(s)
396396
}
397+
// For not rootless container, if there is no init process and no cgroup,
398+
// it means that the container is not running.
399+
if errors.Is(err, ErrCgroupNotExist) && !c.hasInit() {
400+
err = ErrNotRunning
401+
}
397402
return fmt.Errorf("unable to kill all processes: %w", err)
398403
}
399404
return nil

libcontainer/error.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package libcontainer
33
import "errors"
44

55
var (
6-
ErrExist = errors.New("container with given ID already exists")
7-
ErrInvalidID = errors.New("invalid container ID format")
8-
ErrNotExist = errors.New("container does not exist")
9-
ErrPaused = errors.New("container paused")
10-
ErrRunning = errors.New("container still running")
11-
ErrNotRunning = errors.New("container not running")
12-
ErrNotPaused = errors.New("container not paused")
6+
ErrExist = errors.New("container with given ID already exists")
7+
ErrInvalidID = errors.New("invalid container ID format")
8+
ErrNotExist = errors.New("container does not exist")
9+
ErrPaused = errors.New("container paused")
10+
ErrRunning = errors.New("container still running")
11+
ErrNotRunning = errors.New("container not running")
12+
ErrNotPaused = errors.New("container not paused")
13+
ErrCgroupNotExist = errors.New("cgroup not exist")
1314
)

libcontainer/init_linux.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -695,11 +695,9 @@ func setupPersonality(config *configs.Config) error {
695695

696696
// signalAllProcesses freezes then iterates over all the processes inside the
697697
// manager's cgroups sending the signal s to them.
698-
//
699-
// signalAllProcesses returns ErrNotRunning when the cgroup does not exist.
700698
func signalAllProcesses(m cgroups.Manager, s unix.Signal) error {
701699
if !m.Exists() {
702-
return ErrNotRunning
700+
return ErrCgroupNotExist
703701
}
704702
// Use cgroup.kill, if available.
705703
if s == unix.SIGKILL {

0 commit comments

Comments
 (0)