]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
load-fragment: Use parse_cpu_set in CPUAffinity support 1382/head
authorFilipe Brandenburger <filbranden@google.com>
Fri, 25 Sep 2015 02:25:20 +0000 (19:25 -0700)
committerFilipe Brandenburger <filbranden@google.com>
Fri, 25 Sep 2015 02:31:28 +0000 (19:31 -0700)
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.

src/core/load-fragment.c

index f42bee4fa91ba382d9ea028881788f4db1fe5c30..a13f42b5e0106fb1b6e02af1372d8402addfc2a1 100644 (file)
@@ -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;
 }