From 951dccd3ff7f96fbdbcc8130c3517f09044e609d Mon Sep 17 00:00:00 2001 From: Lokesh Mandvekar Date: Thu, 22 Feb 2024 15:13:40 +0530 Subject: [PATCH] cgroups: reuse version check from c/common [NO NEW TESTS NEEDED] Signed-off-by: Lokesh Mandvekar Signed-off-by: Daniel J Walsh --- info.go | 3 ++- util/util.go | 7 ------- util/util_linux.go | 20 -------------------- 3 files changed, 2 insertions(+), 28 deletions(-) delete mode 100644 util/util_linux.go diff --git a/info.go b/info.go index 85e570ce7..72e1050ab 100644 --- a/info.go +++ b/info.go @@ -12,6 +12,7 @@ import ( internalUtil "github.com/containers/buildah/internal/util" putil "github.com/containers/buildah/pkg/util" "github.com/containers/buildah/util" + "github.com/containers/common/pkg/cgroups" "github.com/containers/storage" "github.com/containers/storage/pkg/system" "github.com/containers/storage/pkg/unshare" @@ -50,7 +51,7 @@ func hostInfo() map[string]interface{} { info["cpus"] = runtime.NumCPU() info["rootless"] = unshare.IsRootless() - unified, err := util.IsCgroup2UnifiedMode() + unified, err := cgroups.IsCgroup2UnifiedMode() if err != nil { logrus.Error(err, "err reading cgroups mode") } diff --git a/util/util.go b/util/util.go index 74fecf0b7..b72353af2 100644 --- a/util/util.go +++ b/util/util.go @@ -9,7 +9,6 @@ import ( "path/filepath" "sort" "strings" - "sync" "syscall" "github.com/containers/buildah/define" @@ -376,12 +375,6 @@ func TruncateString(str string, to int) string { return newStr } -var ( - isUnifiedOnce sync.Once - isUnified bool - isUnifiedErr error -) - // fileExistsAndNotADir - Check to see if a file exists // and that it is not a directory. func fileExistsAndNotADir(path string) (bool, error) { diff --git a/util/util_linux.go b/util/util_linux.go deleted file mode 100644 index cca1f9e7e..000000000 --- a/util/util_linux.go +++ /dev/null @@ -1,20 +0,0 @@ -package util - -import ( - "syscall" - - "golang.org/x/sys/unix" -) - -// IsCgroup2UnifiedMode returns whether we are running in cgroup 2 cgroup2 mode. -func IsCgroup2UnifiedMode() (bool, error) { - isUnifiedOnce.Do(func() { - var st syscall.Statfs_t - if err := syscall.Statfs("/sys/fs/cgroup", &st); err != nil { - isUnified, isUnifiedErr = false, err - } else { - isUnified, isUnifiedErr = st.Type == unix.CGROUP2_SUPER_MAGIC, nil - } - }) - return isUnified, isUnifiedErr -}