Skip to content

Commit 7f94bba

Browse files
committed
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.57 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>
1 parent 83e6acb commit 7f94bba

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

run_linux.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net"
1111
"os"
1212
"path/filepath"
13+
"strconv"
1314
"strings"
1415
"syscall"
1516

@@ -227,6 +228,24 @@ func (b *Builder) Run(command []string, options RunOptions) error {
227228
spec := g.Config
228229
g = nil
229230

231+
// Override a buggy resource limit default that containers/common could supply before
232+
// https://github.com/containers/common/pull/2199 fixed it.
233+
if kernelPidMaxBytes, err := os.ReadFile("/proc/sys/kernel/pid_max"); err == nil {
234+
kernelPidMaxString := strings.TrimSpace(string(kernelPidMaxBytes))
235+
if kernelPidMaxValue, err := strconv.ParseUint(kernelPidMaxString, 10, 64); err == nil {
236+
const rlimitDefaultValue = 1024 * 1024
237+
var filteredLimits []specs.POSIXRlimit
238+
for _, rlimit := range spec.Process.Rlimits {
239+
if rlimit.Type == "RLIMIT_NPROC" && rlimit.Soft == kernelPidMaxValue && rlimit.Hard == kernelPidMaxValue {
240+
rlimit.Soft, rlimit.Hard = rlimitDefaultValue, rlimitDefaultValue
241+
logrus.Debugf("overrode RLIMIT_NPROC set to kernel system-wide process limit with %d", rlimitDefaultValue)
242+
}
243+
filteredLimits = append(filteredLimits, rlimit)
244+
}
245+
spec.Process.Rlimits = filteredLimits
246+
}
247+
}
248+
230249
// Set the seccomp configuration using the specified profile name. Some syscalls are
231250
// allowed if certain capabilities are to be granted (example: CAP_SYS_CHROOT and chroot),
232251
// so we sorted out the capabilities lists first.

0 commit comments

Comments
 (0)