Skip to content

Commit ddee36c

Browse files
nalinddashea
authored andcommitted
[release-1.21] Partially work around containers/common
... setting RLIMIT_NPROC wrong The version of containers/common we're currently using on this branch included a bug which was later fixed by containers/common#2199. If we get an update on its v0.60 branch which includes that fix, we can drop this patch from this branch, but until then, work around the part that breaks our tests. Signed-off-by: Nalin Dahyabhai <nalin@redhat.com> Signed-off-by: tomsweeneyredhat <tsweeney@redhat.com>
1 parent c82a9b9 commit ddee36c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

run_linux.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,23 @@ func (b *Builder) Run(command []string, options RunOptions) error {
167167
spec := g.Config
168168
g = nil
169169

170+
// Override a buggy resource limit default that containers/common could supply before
171+
// https://github.com/containers/common/pull/2199 fixed it.
172+
if kernelPidMaxBytes, err := os.ReadFile("/proc/sys/kernel/pid_max"); err == nil {
173+
kernelPidMaxString := strings.TrimSpace(string(kernelPidMaxBytes))
174+
if kernelPidMaxValue, err := strconv.ParseUint(kernelPidMaxString, 10, 64); err == nil {
175+
var filteredLimits []specs.POSIXRlimit
176+
for _, rlimit := range spec.Process.Rlimits {
177+
if rlimit.Type == "RLIMIT_NPROC" && rlimit.Soft == kernelPidMaxValue && rlimit.Hard == kernelPidMaxValue {
178+
rlimit.Soft, rlimit.Hard = define.RLimitDefaultValue, define.RLimitDefaultValue
179+
logrus.Debugf("overrode RLIMIT_NPROC set to kernel system-wide process limit with %d", define.RLimitDefaultValue)
180+
}
181+
filteredLimits = append(filteredLimits, rlimit)
182+
}
183+
spec.Process.Rlimits = filteredLimits
184+
}
185+
}
186+
170187
// Set the seccomp configuration using the specified profile name. Some syscalls are
171188
// allowed if certain capabilities are to be granted (example: CAP_SYS_CHROOT and chroot),
172189
// so we sorted out the capabilities lists first.

0 commit comments

Comments
 (0)