Skip to content

Commit 5241c92

Browse files
committed
Always try to set nofile limit
Try to set nofile limit to RLimitDefaultValue - this could potentially increase the limit past the current hard limit in non-rootless environments. This makes buildah behaviour match podman when a non-rootless environment has lower limits set. Signed-off-by: Chris Reeves <[email protected]>
1 parent 1036cfd commit 5241c92

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

run_linux.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -1003,10 +1003,21 @@ func addRlimits(ulimit []string, g *generate.Generator, defaultUlimits []string)
10031003
g.AddProcessRlimits("RLIMIT_"+strings.ToUpper(ul.Name), uint64(ul.Hard), uint64(ul.Soft))
10041004
}
10051005
if !nofileSet {
1006-
// For nofile, podman sets both hard and soft limits to min(hard limit, RLimitDefaultValue)
1007-
// regardless of rootlessness (see cmd/podman/early_init_linux.go).
1008-
max := define.RLimitDefaultValue
1006+
// For nofile, podman first tries to set both the hard and soft limits for the current
1007+
// process to RLimitDefaultValue - this will be successful in most (but not all)
1008+
// non-rootless environments. If this fails (e.g. in a rootless environment) it will ensure
1009+
// that the soft limit for the current process is increased to match the hard limit (see
1010+
// cmd/podman/early_init_linux.go). We simply fire and forget the call to Setrlimit() here,
1011+
// because if it fails we effectively handle setting soft to hard in the call to
1012+
// AddProcessRlimits() later on.
10091013
var rlimit unix.Rlimit
1014+
rlimit.Cur = define.RLimitDefaultValue
1015+
rlimit.Max = define.RLimitDefaultValue
1016+
unix.Setrlimit(unix.RLIMIT_NOFILE, &rlimit)
1017+
1018+
// Set both hard and soft limits to min(hard limit, RLimitDefaultValue) regardless of
1019+
// rootlessness.
1020+
max := define.RLimitDefaultValue
10101021
if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rlimit); err == nil {
10111022
if rlimit.Max < max {
10121023
max = rlimit.Max

tests/run.bats

+5
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,11 @@ function configure_and_check_user() {
524524

525525
_prefetch alpine
526526

527+
# drop limits prior to tests - this tests the ability of non-rootless containers to increase
528+
# file limits to match those of podman
529+
ulimit -S -n 1024
530+
ulimit -H -n 1024
531+
527532
run_buildah from --quiet --pull=false $WITH_POLICY_JSON alpine
528533
cid=$output
529534
run podman run --rm alpine sh -c "awk '/open files/{print \$4 \"/\" \$5}' /proc/self/limits"

0 commit comments

Comments
 (0)