Skip to content

Commit a2c1a2d

Browse files
committed
podman: bump RLIMIT_NOFILE also without CAP_SYS_RESOURCE
If we are not able to make arbitrary changes to the RLIMIT_NOFILE when lacking CAP_SYS_RESOURCE, don't fail but bump the limit to the maximum allowed. In this way the same code path works with rootless mode. Closes: containers#2123 Signed-off-by: Giuseppe Scrivano <[email protected]>
1 parent 0f6535c commit a2c1a2d

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

cmd/podman/main.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,20 @@ func main() {
148148
logrus.SetLevel(level)
149149
}
150150

151-
// Only if not rootless, set rlimits for open files.
152-
// We open numerous FDs for ports opened
153-
if !rootless.IsRootless() {
154-
rlimits := new(syscall.Rlimit)
155-
rlimits.Cur = 1048576
156-
rlimits.Max = 1048576
151+
rlimits := new(syscall.Rlimit)
152+
rlimits.Cur = 1048576
153+
rlimits.Max = 1048576
154+
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, rlimits); err != nil {
155+
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, rlimits); err != nil {
156+
return errors.Wrapf(err, "error getting rlimits")
157+
}
158+
rlimits.Cur = rlimits.Max
157159
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, rlimits); err != nil {
158160
return errors.Wrapf(err, "error setting new rlimits")
159161
}
160-
} else {
162+
}
163+
164+
if rootless.IsRootless() {
161165
logrus.Info("running as rootless")
162166
}
163167

libpod/container_easyjson.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)