diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-10-28 13:06:56 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-10-28 13:06:56 +0100 |
commit | e3d285e6c0fb5a63e48d97f9bec1ba6d4ec132aa (patch) | |
tree | c2afa8ccfccfa7e464792f52e871e99281597f3f /src/basic/cpu-set-util.c | |
parent | df5b3e1840a373dca1e3da5b81540b7862994ab4 (diff) | |
parent | 71b1c27a406271b71f64487ae70b58f44a4a37f0 (diff) |
Merge pull request #1699 from filbranden/cpuaffinity9
cpu-set-util: Support ranges in parse_cpu_set_and_warn (v4)
Diffstat (limited to 'src/basic/cpu-set-util.c')
-rw-r--r-- | src/basic/cpu-set-util.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/basic/cpu-set-util.c b/src/basic/cpu-set-util.c index 9122ea5d48..4950c66767 100644 --- a/src/basic/cpu-set-util.c +++ b/src/basic/cpu-set-util.c @@ -72,14 +72,12 @@ int parse_cpu_set_and_warn( for (;;) { _cleanup_free_ char *word = NULL; - unsigned cpu; + unsigned cpu, cpu_lower, cpu_upper; int r; - r = extract_first_word(&rvalue, &word, WHITESPACE, EXTRACT_QUOTES); - if (r < 0) { - log_syntax(unit, LOG_ERR, filename, line, r, "Invalid value for %s: %s", lvalue, whole_rvalue); - return r; - } + r = extract_first_word(&rvalue, &word, WHITESPACE ",", EXTRACT_QUOTES); + if (r < 0) + return log_syntax(unit, LOG_ERR, filename, line, r, "Invalid value for %s: %s", lvalue, whole_rvalue); if (r == 0) break; @@ -89,13 +87,17 @@ int parse_cpu_set_and_warn( return log_oom(); } - r = safe_atou(word, &cpu); - if (r < 0 || cpu >= ncpus) { - log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse CPU affinity '%s'", rvalue); - return -EINVAL; - } - - CPU_SET_S(cpu, CPU_ALLOC_SIZE(ncpus), c); + r = parse_range(word, &cpu_lower, &cpu_upper); + if (r < 0) + return log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse CPU affinity '%s'", word); + if (cpu_lower >= ncpus || cpu_upper >= ncpus) + return log_syntax(unit, LOG_ERR, filename, line, EINVAL, "CPU out of range '%s' ncpus is %u", word, ncpus); + + if (cpu_lower > cpu_upper) + log_syntax(unit, LOG_WARNING, filename, line, 0, "Range '%s' is invalid, %u > %u", word, cpu_lower, cpu_upper); + else + for (cpu = cpu_lower; cpu <= cpu_upper; cpu++) + CPU_SET_S(cpu, CPU_ALLOC_SIZE(ncpus), c); } /* On success, sets *cpu_set and returns ncpus for the system. */ |