mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
don't panic when /sys/fs/cgroup is missing for rootless
Signed-off-by: Cory Bennett <cbennett@netflix.com>
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/opencontainers/runc/libcontainer/cgroups/fscommon"
|
"github.com/opencontainers/runc/libcontainer/cgroups/fscommon"
|
||||||
|
"github.com/opencontainers/runc/libcontainer/system"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
@@ -34,8 +35,15 @@ var (
|
|||||||
func IsCgroup2UnifiedMode() bool {
|
func IsCgroup2UnifiedMode() bool {
|
||||||
isUnifiedOnce.Do(func() {
|
isUnifiedOnce.Do(func() {
|
||||||
var st unix.Statfs_t
|
var st unix.Statfs_t
|
||||||
if err := unix.Statfs(unifiedMountpoint, &st); err != nil {
|
err := unix.Statfs(unifiedMountpoint, &st)
|
||||||
panic("cannot statfs cgroup root")
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) && system.RunningInUserNS() {
|
||||||
|
// ignore the "not found" error if running in userns
|
||||||
|
logrus.WithError(err).Debugf("%s missing, assuming cgroup v1", unifiedMountpoint)
|
||||||
|
isUnified = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
panic(fmt.Sprintf("cannot statfs cgroup root: %s", err))
|
||||||
}
|
}
|
||||||
isUnified = st.Type == unix.CGROUP2_SUPER_MAGIC
|
isUnified = st.Type == unix.CGROUP2_SUPER_MAGIC
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user