Skip to content

Commit dbf9ebd

Browse files
committed
Fix: cgroup2: Check cgroup existence on Load
Signed-off-by: Berbe <4251220+Berbe@users.noreply.github.com>
1 parent c4c9976 commit dbf9ebd

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

cgroup2/manager.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ func Load(group string, opts ...InitOpts) (*Manager, error) {
224224
return nil, err
225225
}
226226
path := filepath.Join(c.mountpoint, group)
227+
_, err := os.Stat(path)
228+
if err != nil {
229+
return nil, err
230+
}
227231
return &Manager{
228232
unifiedMountpoint: c.mountpoint,
229233
path: path,

cgroup2/manager_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package cgroup2
1919
import (
2020
"context"
2121
"fmt"
22+
"io/fs"
2223
"os"
2324
"os/exec"
2425
"syscall"
@@ -477,3 +478,11 @@ func TestLoadOKWhenExistent(t *testing.T) {
477478
_, err = Load(group)
478479
require.NoError(t, err)
479480
}
481+
482+
func TestLoadErrorsWhenNonExistent(t *testing.T) {
483+
checkCgroupMode(t)
484+
group := "/nonexistent"
485+
486+
_, err := Load(group)
487+
require.ErrorIs(t, err, fs.ErrNotExist)
488+
}

0 commit comments

Comments
 (0)