Skip to content

Commit 234e773

Browse files
nalindTomSweeneyRedHat
authored andcommitted
[release-1.37] 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 ba3af50 commit 234e773

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

run_linux.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"os"
1111
"path/filepath"
12+
"strconv"
1213
"strings"
1314
"syscall"
1415

@@ -330,6 +331,23 @@ func (b *Builder) Run(command []string, options RunOptions) error {
330331
spec := g.Config
331332
g = nil
332333

334+
// Override a buggy resource limit default that containers/common could supply before
335+
// https://github.com/containers/common/pull/2199 fixed it.
336+
if kernelPidMaxBytes, err := os.ReadFile("/proc/sys/kernel/pid_max"); err == nil {
337+
kernelPidMaxString := strings.TrimSpace(string(kernelPidMaxBytes))
338+
if kernelPidMaxValue, err := strconv.ParseUint(kernelPidMaxString, 10, 64); err == nil {
339+
var filteredLimits []specs.POSIXRlimit
340+
for _, rlimit := range spec.Process.Rlimits {
341+
if rlimit.Type == "RLIMIT_NPROC" && rlimit.Soft == kernelPidMaxValue && rlimit.Hard == kernelPidMaxValue {
342+
rlimit.Soft, rlimit.Hard = define.RLimitDefaultValue, define.RLimitDefaultValue
343+
logrus.Debugf("overrode RLIMIT_NPROC set to kernel system-wide process limit with %d", define.RLimitDefaultValue)
344+
}
345+
filteredLimits = append(filteredLimits, rlimit)
346+
}
347+
spec.Process.Rlimits = filteredLimits
348+
}
349+
}
350+
333351
// Set the seccomp configuration using the specified profile name. Some syscalls are
334352
// allowed if certain capabilities are to be granted (example: CAP_SYS_CHROOT and chroot),
335353
// so we sorted out the capabilities lists first.

0 commit comments

Comments
 (0)