Files
podman/pkg/specgen/resources_linux.go
T
Victor Irzak f41dc744b2 Omit unlimited pids limit for rootless cgroupfs
Rootless with the cgroupfs manager the pids controller is often not
delegated, as on WSL machines. The default path already skips the pids
limit there, but an explicit unlimited value (--pids-limit -1 or 0, the
PidsLimit=0 every Docker client sends, or pids.limit 0 on the libpod
API) still reached crun, which then failed with "controller `pids` is
not available".

A new cgroup has no pids limit anyway, so drop an unlimited limit in
that case. Finite limits are left as they are.

Fixes: https://github.com/podman-container-tools/podman/issues/29909
Signed-off-by: Victor Irzak <victor.irzak@zomp.com>
2026-10-06 06:10:13 -04:00

32 lines
894 B
Go

package specgen
import (
spec "github.com/opencontainers/runtime-spec/specs-go"
"go.podman.io/common/pkg/config"
"go.podman.io/storage/pkg/unshare"
)
func (s *SpecGenerator) InitResourceLimits(rtc *config.Config) {
if s.ResourceLimits == nil || s.ResourceLimits.Pids == nil {
if s.CgroupsMode != "disabled" {
limit := rtc.PidsLimit()
if limit != 0 {
if s.ResourceLimits == nil {
s.ResourceLimits = &spec.LinuxResources{}
}
s.ResourceLimits.Pids = &spec.LinuxPids{
Limit: &limit,
}
}
}
return
}
// Rootless with cgroupfs the pids controller is often not delegated, and a
// new cgroup has no pids limit anyway, so do not ask the runtime to set one.
if limit := s.ResourceLimits.Pids.Limit; (limit == nil || *limit <= 0) &&
unshare.IsRootless() && rtc.Engine.CgroupManager != config.SystemdCgroupsManager {
s.ResourceLimits.Pids = nil
}
}