Skip to content

Commit 1e8c836

Browse files
committed
main: exit if no Cgroups v2
Signed-off-by: Lokesh Mandvekar <[email protected]>
1 parent 559ee10 commit 1e8c836

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

cmd/buildah/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
rspecs "github.com/opencontainers/runtime-spec/specs-go"
1919
"github.com/sirupsen/logrus"
2020
"github.com/spf13/cobra"
21+
cgroupv2 "go.podman.io/common/pkg/cgroupv2"
2122
"go.podman.io/common/pkg/config"
2223
"go.podman.io/storage"
2324
"go.podman.io/storage/pkg/unshare"
@@ -231,6 +232,15 @@ func main() {
231232
return
232233
}
233234

235+
cgroupsv2, err := cgroupv2.Enabled()
236+
if err != nil {
237+
logrus.Error(err, "Error reading cgroups mode")
238+
}
239+
if !cgroupsv2 {
240+
fmt.Println("Could not detect Cgroups v2 on your system. Please switch to Cgroups v2.")
241+
os.Exit(1)
242+
}
243+
234244
// Hard code TMPDIR functions to use $TMPDIR or /var/tmp
235245
os.Setenv("TMPDIR", parse.GetTempDir())
236246

info.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/containers/buildah/util"
1515
v1 "github.com/opencontainers/image-spec/specs-go/v1"
1616
"github.com/sirupsen/logrus"
17-
"go.podman.io/common/pkg/cgroups"
1817
"go.podman.io/storage"
1918
"go.podman.io/storage/pkg/system"
2019
"go.podman.io/storage/pkg/unshare"
@@ -51,10 +50,6 @@ func hostInfo() map[string]any {
5150
info["cpus"] = runtime.NumCPU()
5251
info["rootless"] = unshare.IsRootless()
5352

54-
_, err := cgroups.IsCgroup2UnifiedMode()
55-
if err != nil {
56-
logrus.Error(err, "err reading cgroups mode")
57-
}
5853
ociruntime := util.Runtime()
5954
info["CgroupVersion"] = "v2"
6055
info["OCIRuntime"] = ociruntime

vendor/go.podman.io/common/pkg/cgroupv2/cgroups_linux.go

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/go.podman.io/common/pkg/cgroupv2/cgroups_unsupported.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ go.podman.io/common/pkg/apparmor/internal/supported
489489
go.podman.io/common/pkg/auth
490490
go.podman.io/common/pkg/capabilities
491491
go.podman.io/common/pkg/cgroups
492+
go.podman.io/common/pkg/cgroupv2
492493
go.podman.io/common/pkg/chown
493494
go.podman.io/common/pkg/completion
494495
go.podman.io/common/pkg/config

0 commit comments

Comments
 (0)