rlimit-util: introduce setrlimit_closest_all()
This new call applies all configured resource limits in one.
This commit is contained in:
@@ -42,6 +42,32 @@ int setrlimit_closest(int resource, const struct rlimit *rlim) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int setrlimit_closest_all(const struct rlimit *const *rlim, int *which_failed) {
|
||||
int i, r;
|
||||
|
||||
assert(rlim);
|
||||
|
||||
/* On failure returns the limit's index that failed in *which_failed, but only if non-NULL */
|
||||
|
||||
for (i = 0; i < _RLIMIT_MAX; i++) {
|
||||
if (!rlim[i])
|
||||
continue;
|
||||
|
||||
r = setrlimit_closest(i, rlim[i]);
|
||||
if (r < 0) {
|
||||
if (which_failed)
|
||||
*which_failed = i;
|
||||
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
if (which_failed)
|
||||
*which_failed = -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rlimit_parse_u64(const char *val, rlim_t *ret) {
|
||||
uint64_t u;
|
||||
int r;
|
||||
|
||||
@@ -16,6 +16,7 @@ int rlimit_from_string(const char *s) _pure_;
|
||||
int rlimit_from_string_harder(const char *s) _pure_;
|
||||
|
||||
int setrlimit_closest(int resource, const struct rlimit *rlim);
|
||||
int setrlimit_closest_all(const struct rlimit * const *rlim, int *which_failed);
|
||||
|
||||
int rlimit_parse_one(int resource, const char *val, rlim_t *ret);
|
||||
int rlimit_parse(int resource, const char *val, struct rlimit *ret);
|
||||
|
||||
Reference in New Issue
Block a user