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.
This commit is contained in:
parent
a17c17122c
commit
0bbee2c226
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue