From: Lennart Poettering Date: Mon, 7 May 2018 15:56:06 +0000 (+0200) Subject: rlimit-util: tweak setrlimit_closest() a bit X-Git-Tag: v239~243^2~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=114c55f2d52808c8c3027d3cf4f7e3453f0a28d6;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/basic/rlimit-util.c b/src/basic/rlimit-util.c index dccc4e60e1a..57f90474d8f 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);