]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cpu-set-util: Accept commas as separators in parse_cpu_set_and_warn
authorFilipe Brandenburger <filbranden@google.com>
Fri, 25 Sep 2015 11:45:22 +0000 (04:45 -0700)
committerFilipe Brandenburger <filbranden@google.com>
Wed, 28 Oct 2015 00:39:58 +0000 (17:39 -0700)
Tested CPUAffinity settings on both a service unit and in system.conf
and confirmed they work as expected.

Added a new test to confirm that trailing commas and spaces work and to
prevent any regressions in that area.

src/basic/cpu-set-util.c
src/test/test-util.c

index 9122ea5d4847096dc1e0bdabbc37c54b2a51a936..441144d5cca7ba4af33db4f664456b7973d71d85 100644 (file)
@@ -75,7 +75,7 @@ int parse_cpu_set_and_warn(
                 unsigned cpu;
                 int r;
 
-                r = extract_first_word(&rvalue, &word, WHITESPACE, EXTRACT_QUOTES);
+                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;
index ffde10c7e1d6fe134bfd3860745b575e346fa806..b0eb77592ef357ab4faf812ae7e207f716a2021f 100644 (file)
@@ -1012,8 +1012,21 @@ static void test_parse_cpu_set(void) {
 
         /* Use commas as separators */
         ncpus = parse_cpu_set_and_warn("0,1,2,3 8,9,10,11", &c, NULL, "fake", 1, "CPUAffinity");
-        assert_se(ncpus < 0);
-        assert_se(!c);
+        assert_se(ncpus >= 1024);
+        assert_se(CPU_COUNT_S(CPU_ALLOC_SIZE(ncpus), c) == 8);
+        for (cpu = 0; cpu < 4; cpu++)
+                assert_se(CPU_ISSET_S(cpu, CPU_ALLOC_SIZE(ncpus), c));
+        for (cpu = 8; cpu < 12; cpu++)
+                assert_se(CPU_ISSET_S(cpu, CPU_ALLOC_SIZE(ncpus), c));
+        c = mfree(c);
+
+        /* Commas with spaces (and trailing comma, space) */
+        ncpus = parse_cpu_set_and_warn("0, 1, 2, 3, 4, 5, 6, 7, ", &c, NULL, "fake", 1, "CPUAffinity");
+        assert_se(ncpus >= 1024);
+        assert_se(CPU_COUNT_S(CPU_ALLOC_SIZE(ncpus), c) == 8);
+        for (cpu = 0; cpu < 8; cpu++)
+                assert_se(CPU_ISSET_S(cpu, CPU_ALLOC_SIZE(ncpus), c));
+        c = mfree(c);
 
         /* Ranges */
         ncpus = parse_cpu_set_and_warn("0-3,8-11", &c, NULL, "fake", 1, "CPUAffinity");