basic: split parsing of the OOM score adjust value into its own function in parse-util.c

And port config_parse_exec_oom_score_adjust() over to use it.

While we are at it, let's also fix config_parse_exec_oom_score_adjust()
to accept an empty string for turning off OOM score adjustments set
earlier.
This commit is contained in:
Lennart Poettering
2018-05-17 20:47:21 +02:00
parent 66edd96310
commit e9eb2c02f0
3 changed files with 39 additions and 15 deletions
+17
View File
@@ -676,3 +676,20 @@ int parse_dev(const char *s, dev_t *ret) {
*ret = d;
return 0;
}
int parse_oom_score_adjust(const char *s, int *ret) {
int r, v;
assert(s);
assert(ret);
r = safe_atoi(s, &v);
if (r < 0)
return r;
if (v < OOM_SCORE_ADJ_MIN || v > OOM_SCORE_ADJ_MAX)
return -ERANGE;
*ret = v;
return 0;
}
+2
View File
@@ -118,3 +118,5 @@ int parse_percent(const char *p);
int parse_nice(const char *p, int *ret);
int parse_ip_port(const char *s, uint16_t *ret);
int parse_oom_score_adjust(const char *s, int *ret);