Skip to content

Commit 0b7f500

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 116af5e commit 0b7f500

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
@@ -167,6 +167,24 @@ 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+
const rlimitDefaultValue = 1024 * 1024
176+
var filteredLimits []specs.POSIXRlimit
177+
for _, rlimit := range spec.Process.Rlimits {
178+
if rlimit.Type == "RLIMIT_NPROC" && rlimit.Soft == kernelPidMaxValue && rlimit.Hard == kernelPidMaxValue {
179+
rlimit.Soft, rlimit.Hard = rlimitDefaultValue, rlimitDefaultValue
180+
logrus.Debugf("overrode RLIMIT_NPROC set to kernel system-wide process limit with %d", rlimitDefaultValue)
181+
}
182+
filteredLimits = append(filteredLimits, rlimit)
183+
}
184+
spec.Process.Rlimits = filteredLimits
185+
}
186+
}
187+
170188
// Set the seccomp configuration using the specified profile name. Some syscalls are
171189
// allowed if certain capabilities are to be granted (example: CAP_SYS_CHROOT and chroot),
172190
// so we sorted out the capabilities lists first.

0 commit comments

Comments
 (0)