Skip to content

Commit 9c3b465

Browse files
committed
libct/cg: IsCgroup2HybridMode: don't panic
In case statfs("/sys/fs/cgroup/unified") fails with any error other than ENOENT, current code panics. As IsCgroup2HybridMode is called from libcontainer/cgroups/fs's init function, this means that any user of libcontainer may panic during initialization, which is ugly. Avoid panicking; instead, do not enable hybrid hierarchy support and report the error (under debug level, not to confuse anyone). Basically, replace the panic with "turn off hybrid mode support" (which makes total sense since we were unable to statfs its root). Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 86d6898 commit 9c3b465

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

libcontainer/cgroups/utils.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,11 @@ func IsCgroup2HybridMode() bool {
5555
var st unix.Statfs_t
5656
err := unix.Statfs(hybridMountpoint, &st)
5757
if err != nil {
58-
if os.IsNotExist(err) {
59-
// ignore the "not found" error
60-
isHybrid = false
61-
return
58+
isHybrid = false
59+
if !os.IsNotExist(err) {
60+
// Report unexpected errors.
61+
logrus.WithError(err).Debugf("statfs(%q) failed", hybridMountpoint)
6262
}
63-
panic(fmt.Sprintf("cannot statfs cgroup root: %s", err))
6463
}
6564
isHybrid = st.Type == unix.CGROUP2_SUPER_MAGIC
6665
})

0 commit comments

Comments
 (0)