summaryrefslogtreecommitdiff
path: root/pkg/cgroups
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/cgroups')
-rw-r--r--pkg/cgroups/cgroups.go26
-rw-r--r--pkg/cgroups/cgroups_test.go2
2 files changed, 17 insertions, 11 deletions
diff --git a/pkg/cgroups/cgroups.go b/pkg/cgroups/cgroups.go
index 285fd093a..608e1647a 100644
--- a/pkg/cgroups/cgroups.go
+++ b/pkg/cgroups/cgroups.go
@@ -11,7 +11,7 @@ import (
"strconv"
"strings"
- "github.com/containers/podman/v2/pkg/rootless"
+ "github.com/containers/podman/v3/pkg/rootless"
systemdDbus "github.com/coreos/go-systemd/v22/dbus"
"github.com/godbus/dbus/v5"
spec "github.com/opencontainers/runtime-spec/specs-go"
@@ -331,18 +331,24 @@ func Load(path string) (*CgroupControl, error) {
control.additionalControllers = controllers
}
if !cgroup2 {
+ oneExists := false
+ // check that the cgroup exists at least under one controller
for name := range handlers {
p := control.getCgroupv1Path(name)
- if _, err := os.Stat(p); err != nil {
- if os.IsNotExist(err) {
- if rootless.IsRootless() {
- return nil, ErrCgroupV1Rootless
- }
- // compatible with the error code
- // used by containerd/cgroups
- return nil, ErrCgroupDeleted
- }
+ if _, err := os.Stat(p); err == nil {
+ oneExists = true
+ break
+ }
+ }
+
+ // if there is no controller at all, raise an error
+ if !oneExists {
+ if rootless.IsRootless() {
+ return nil, ErrCgroupV1Rootless
}
+ // compatible with the error code
+ // used by containerd/cgroups
+ return nil, ErrCgroupDeleted
}
}
return control, nil
diff --git a/pkg/cgroups/cgroups_test.go b/pkg/cgroups/cgroups_test.go
index 54315f7be..22d5efb76 100644
--- a/pkg/cgroups/cgroups_test.go
+++ b/pkg/cgroups/cgroups_test.go
@@ -3,7 +3,7 @@ package cgroups
import (
"testing"
- "github.com/containers/podman/v2/pkg/rootless"
+ "github.com/containers/podman/v3/pkg/rootless"
spec "github.com/opencontainers/runtime-spec/specs-go"
)