diff options
author | Filipe Brandenburger <filbranden@google.com> | 2015-09-24 19:25:20 -0700 |
---|---|---|
committer | Filipe Brandenburger <filbranden@google.com> | 2015-09-24 19:31:28 -0700 |
commit | 9d5ca7f882d3c65f6d85e9fc727a0eea3262aaf9 (patch) | |
tree | 2761544b392e9d5efe8d9c901640de15a1104fa9 /src/core | |
parent | 5f05235f13ab0ba6b7555f0a632d82a316ee869c (diff) |
load-fragment: Use parse_cpu_set in CPUAffinity support
Tested with a dummy service running 'sleep', modifying its CPUAffinity,
restarting the service and checking the ^Cpus_allowed entries in the
/proc/PID/status file.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/load-fragment.c | 48 |
1 files changed, 14 insertions, 34 deletions
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index f42bee4fa9..a13f42b5e0 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -875,50 +875,30 @@ int config_parse_exec_cpu_affinity(const char *unit, void *userdata) { ExecContext *c = data; - const char *word, *state; - size_t l; + _cleanup_cpu_free_ cpu_set_t *cpuset = NULL; + int ncpus; assert(filename); assert(lvalue); assert(rvalue); assert(data); - if (isempty(rvalue)) { - /* An empty assignment resets the CPU list */ - if (c->cpuset) - CPU_FREE(c->cpuset); - c->cpuset = NULL; - return 0; - } + ncpus = parse_cpu_set(rvalue, &cpuset, unit, filename, line, lvalue); - FOREACH_WORD_QUOTED(word, l, rvalue, state) { - _cleanup_free_ char *t = NULL; - int r; - unsigned cpu; + if (ncpus < 0) + return ncpus; - t = strndup(word, l); - if (!t) - return log_oom(); + if (c->cpuset) + CPU_FREE(c->cpuset); - r = safe_atou(t, &cpu); - - if (!c->cpuset) { - c->cpuset = cpu_set_malloc(&c->cpuset_ncpus); - if (!c->cpuset) - return log_oom(); - } - - if (r < 0 || cpu >= c->cpuset_ncpus) { - log_syntax(unit, LOG_ERR, filename, line, ERANGE, - "Failed to parse CPU affinity '%s', ignoring: %s", t, rvalue); - return 0; - } - - CPU_SET_S(cpu, CPU_ALLOC_SIZE(c->cpuset_ncpus), c->cpuset); + if (ncpus == 0) + /* An empty assignment resets the CPU list */ + c->cpuset = NULL; + else { + c->cpuset = cpuset; + cpuset = NULL; } - if (!isempty(state)) - log_syntax(unit, LOG_WARNING, filename, line, EINVAL, - "Trailing garbage, ignoring."); + c->cpuset_ncpus = ncpus; return 0; } |