mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00

We had a couple of regressions in containers/common in the last release. Before cutting a new release, let's vendor it here. Since 3.0 has been branched, we can vendor a non-release commit of c/common. Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
28 lines
526 B
Go
28 lines
526 B
Go
package cgroupv2
|
|
|
|
import (
|
|
"sync"
|
|
"syscall"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
var (
|
|
isCgroupV2Once sync.Once
|
|
isCgroupV2 bool
|
|
isCgroupV2Err error
|
|
)
|
|
|
|
// Enabled returns whether we are running on cgroup v2
|
|
func Enabled() (bool, error) {
|
|
isCgroupV2Once.Do(func() {
|
|
var st syscall.Statfs_t
|
|
if err := syscall.Statfs("/sys/fs/cgroup", &st); err != nil {
|
|
isCgroupV2, isCgroupV2Err = false, err
|
|
} else {
|
|
isCgroupV2, isCgroupV2Err = st.Type == unix.CGROUP2_SUPER_MAGIC, nil
|
|
}
|
|
})
|
|
return isCgroupV2, isCgroupV2Err
|
|
}
|