From 114c55f2d52808c8c3027d3cf4f7e3453f0a28d6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 7 May 2018 17:56:06 +0200 Subject: [PATCH] rlimit-util: tweak setrlimit_closest() a bit POSIX doesn't declare too clearly how RLIM_INFINITY is set. Let's hence filter it out explicitly early on, just as safety precaution should it be defined weirdly on some arch, for example negative or below the maximum value of the rlim_t type. --- src/basic/rlimit-util.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/basic/rlimit-util.c b/src/basic/rlimit-util.c index dccc4e60e1..57f90474d8 100644 --- a/src/basic/rlimit-util.c +++ b/src/basic/rlimit-util.c @@ -33,6 +33,11 @@ int setrlimit_closest(int resource, const struct rlimit *rlim) { if (getrlimit(resource, &highest) < 0) return -errno; + /* If the hard limit is unbounded anyway, then the EPERM had other reasons, let's propagate the original EPERM + * then */ + if (highest.rlim_max == RLIM_INFINITY) + return -EPERM; + fixed.rlim_cur = MIN(rlim->rlim_cur, highest.rlim_max); fixed.rlim_max = MIN(rlim->rlim_max, highest.rlim_max); -- 2.25.1