cgroups: reuse version check from c/common

[NO NEW TESTS NEEDED]

Signed-off-by: Lokesh Mandvekar <lsm5@redhat.com>
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Lokesh Mandvekar 2024-02-22 15:13:40 +05:30 committed by Daniel J Walsh
parent bbea3eb544
commit 951dccd3ff
No known key found for this signature in database
GPG Key ID: A2DF901DABE2C028
3 changed files with 2 additions and 28 deletions

View File

@ -12,6 +12,7 @@ import (
internalUtil "github.com/containers/buildah/internal/util" internalUtil "github.com/containers/buildah/internal/util"
putil "github.com/containers/buildah/pkg/util" putil "github.com/containers/buildah/pkg/util"
"github.com/containers/buildah/util" "github.com/containers/buildah/util"
"github.com/containers/common/pkg/cgroups"
"github.com/containers/storage" "github.com/containers/storage"
"github.com/containers/storage/pkg/system" "github.com/containers/storage/pkg/system"
"github.com/containers/storage/pkg/unshare" "github.com/containers/storage/pkg/unshare"
@ -50,7 +51,7 @@ func hostInfo() map[string]interface{} {
info["cpus"] = runtime.NumCPU() info["cpus"] = runtime.NumCPU()
info["rootless"] = unshare.IsRootless() info["rootless"] = unshare.IsRootless()
unified, err := util.IsCgroup2UnifiedMode() unified, err := cgroups.IsCgroup2UnifiedMode()
if err != nil { if err != nil {
logrus.Error(err, "err reading cgroups mode") logrus.Error(err, "err reading cgroups mode")
} }

View File

@ -9,7 +9,6 @@ import (
"path/filepath" "path/filepath"
"sort" "sort"
"strings" "strings"
"sync"
"syscall" "syscall"
"github.com/containers/buildah/define" "github.com/containers/buildah/define"
@ -376,12 +375,6 @@ func TruncateString(str string, to int) string {
return newStr return newStr
} }
var (
isUnifiedOnce sync.Once
isUnified bool
isUnifiedErr error
)
// fileExistsAndNotADir - Check to see if a file exists // fileExistsAndNotADir - Check to see if a file exists
// and that it is not a directory. // and that it is not a directory.
func fileExistsAndNotADir(path string) (bool, error) { func fileExistsAndNotADir(path string) (bool, error) {

View File

@ -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
}