summaryrefslogtreecommitdiff
path: root/src/basic/rlimit-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-10-02 08:41:03 +0200
committerLennart Poettering <lennart@poettering.net>2018-10-16 16:33:55 +0200
commit0bbee2c226788ff12d8fa41b5392ad2ceae4d0e0 (patch)
treee4394a9f2622054a2750abfa493acab1cd74d13c /src/basic/rlimit-util.c
parenta17c17122c304ff3f67f1cbf119fa7116315a7df (diff)
downloadsystemd-0bbee2c226788ff12d8fa41b5392ad2ceae4d0e0.tar.gz
rlimit-util: don't call setrlimit() needlessly if it wouldn't change anything
Just a tiny tweak to avoid generating an error if there's no need to.
Diffstat (limited to 'src/basic/rlimit-util.c')
-rw-r--r--src/basic/rlimit-util.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/basic/rlimit-util.c b/src/basic/rlimit-util.c
index d63b85850c..c133f84b7e 100644
--- a/src/basic/rlimit-util.c
+++ b/src/basic/rlimit-util.c
@@ -34,8 +34,15 @@ int setrlimit_closest(int resource, const struct rlimit *rlim) {
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);
+ fixed = (struct rlimit) {
+ .rlim_cur = MIN(rlim->rlim_cur, highest.rlim_max),
+ .rlim_max = MIN(rlim->rlim_max, highest.rlim_max),
+ };
+
+ /* Shortcut things if we wouldn't change anything. */
+ if (fixed.rlim_cur == highest.rlim_cur &&
+ fixed.rlim_max == highest.rlim_max)
+ return 0;
if (setrlimit(resource, &fixed) < 0)
return -errno;