From: Lennart Poettering Date: Tue, 2 Oct 2018 06:41:03 +0000 (+0200) Subject: rlimit-util: don't call setrlimit() needlessly if it wouldn't change anything X-Git-Tag: v240~533^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0bbee2c226788ff12d8fa41b5392ad2ceae4d0e0;p=platform%2Fupstream%2Fsystemd.git 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. --- diff --git a/src/basic/rlimit-util.c b/src/basic/rlimit-util.c index d63b858..c133f84 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;