From e34f6438e97c57f98d4598e86185bc5c9a4e3eed Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 18 Jun 2025 16:56:00 -0700 Subject: [PATCH] libct: State: ensure Resources is not nil Since opencontainers/cgroups v0.0.2 (commit b206a015), all stuct Resources fields are annotated with "omitempty" attribute. As a result, the loaded configuration may have Resources == nil. It is totally OK (rootless containers may have no resources configured) except since commit 6c5441e5, cgroup v1 fs manager requires Resources to be set in the call to NewManager (this is a cgroup v1 deficiency, or maybe our implementation deficiency, or both). To work around this, let's add code to ensure Resources is never nil after loading from state.json. Signed-off-by: Kir Kolyshkin --- libcontainer/factory_linux.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libcontainer/factory_linux.go b/libcontainer/factory_linux.go index 539726dfd..94b55eaa8 100644 --- a/libcontainer/factory_linux.go +++ b/libcontainer/factory_linux.go @@ -164,6 +164,10 @@ func loadState(root string) (*State, error) { if err := json.NewDecoder(f).Decode(&state); err != nil { return nil, err } + // Cgroup v1 fs manager expect Resources to never be nil. + if state.Config.Cgroups.Resources == nil { + state.Config.Cgroups.Resources = &cgroups.Resources{} + } return state, nil }