]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
rlimit-util: tweak setrlimit_closest() a bit
authorLennart Poettering <lennart@poettering.net>
Mon, 7 May 2018 15:56:06 +0000 (17:56 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 17 May 2018 18:40:04 +0000 (20:40 +0200)
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

index dccc4e60e1adaffbc2b0eb1688afac7717168406..57f90474d8f24b57bc708ef7b2ea1e3d0fe6c19d 100644 (file)
@@ -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);