diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-05-07 20:26:38 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-05-17 20:47:21 +0200 |
commit | e9eb2c02f0f08dd1d1de57918b277193aa529832 (patch) | |
tree | fcba55a13340c7316e6d7d91d52bdbe8bfee08de /src/core/load-fragment.c | |
parent | nspawn: add a new --no-new-privileges= cmdline option to nspawn (diff) | |
download | systemd-e9eb2c02f0f08dd1d1de57918b277193aa529832.tar.xz systemd-e9eb2c02f0f08dd1d1de57918b277193aa529832.zip |
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.
Diffstat (limited to '')
-rw-r--r-- | src/core/load-fragment.c | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 85e2b1f53f..6c69f4a55f 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -506,16 +506,17 @@ int config_parse_exec_nice( return 0; } -int config_parse_exec_oom_score_adjust(const char* unit, - const char *filename, - unsigned line, - const char *section, - unsigned section_line, - const char *lvalue, - int ltype, - const char *rvalue, - void *data, - void *userdata) { +int config_parse_exec_oom_score_adjust( + const char* unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { ExecContext *c = data; int oa, r; @@ -525,14 +526,18 @@ int config_parse_exec_oom_score_adjust(const char* unit, assert(rvalue); assert(data); - r = safe_atoi(rvalue, &oa); - if (r < 0) { - log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse the OOM score adjust value, ignoring: %s", rvalue); + if (isempty(rvalue)) { + c->oom_score_adjust_set = false; return 0; } - if (oa < OOM_SCORE_ADJ_MIN || oa > OOM_SCORE_ADJ_MAX) { - log_syntax(unit, LOG_ERR, filename, line, 0, "OOM score adjust value out of range, ignoring: %s", rvalue); + r = parse_oom_score_adjust(rvalue, &oa); + if (r == -ERANGE) { + log_syntax(unit, LOG_ERR, filename, line, r, "OOM score adjust value out of range, ignoring: %s", rvalue); + return 0; + } + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse the OOM score adjust value, ignoring: %s", rvalue); return 0; } |