]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util: rename parse_cpu_set() to parse_cpu_set_and_warn()
authorLennart Poettering <lennart@poettering.net>
Wed, 30 Sep 2015 18:16:51 +0000 (20:16 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 30 Sep 2015 20:26:16 +0000 (22:26 +0200)
It's pretty untypical for our parsing functions to log on their own.
Clarify in the name that this one does.

src/basic/util.c
src/basic/util.h
src/core/load-fragment.c
src/core/main.c
src/test/test-util.c

index b76cb7aa97f6a38f9c210297f4383ec030ea106e..a2a75bdd7f59a45d3865f5694fb00cb2afd0b310 100644 (file)
@@ -2552,25 +2552,26 @@ int fchmod_and_fchown(int fd, mode_t mode, uid_t uid, gid_t gid) {
 }
 
 cpu_set_t* cpu_set_malloc(unsigned *ncpus) {
-        cpu_set_t *r;
+        cpu_set_t *c;
         unsigned n = 1024;
 
         /* Allocates the cpuset in the right size */
 
         for (;;) {
-                if (!(r = CPU_ALLOC(n)))
+                c = CPU_ALLOC(n);
+                if (!c)
                         return NULL;
 
-                if (sched_getaffinity(0, CPU_ALLOC_SIZE(n), r) >= 0) {
-                        CPU_ZERO_S(CPU_ALLOC_SIZE(n), r);
+                if (sched_getaffinity(0, CPU_ALLOC_SIZE(n), c) >= 0) {
+                        CPU_ZERO_S(CPU_ALLOC_SIZE(n), c);
 
                         if (ncpus)
                                 *ncpus = n;
 
-                        return r;
+                        return c;
                 }
 
-                CPU_FREE(r);
+                CPU_FREE(c);
 
                 if (errno != EINVAL)
                         return NULL;
@@ -2579,7 +2580,7 @@ cpu_set_t* cpu_set_malloc(unsigned *ncpus) {
         }
 }
 
-int parse_cpu_set(
+int parse_cpu_set_and_warn(
                 const char *rvalue,
                 cpu_set_t **cpu_set,
                 const char *unit,
@@ -2591,7 +2592,6 @@ int parse_cpu_set(
         _cleanup_cpu_free_ cpu_set_t *c = NULL;
         unsigned ncpus = 0;
 
-        assert(filename);
         assert(lvalue);
         assert(rvalue);
 
index afd906477a69f83d91a438b67b3f195ca7582e14..ff6c39aaa3a52883ea9047e9c71aaf5ee40d7ddc 100644 (file)
@@ -375,7 +375,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(cpu_set_t*, CPU_FREE);
 #define _cleanup_cpu_free_ _cleanup_(CPU_FREEp)
 
 cpu_set_t* cpu_set_malloc(unsigned *ncpus);
-int parse_cpu_set(const char *rvalue, cpu_set_t **cpu_set, const char *unit, const char *filename, unsigned line, const char *lvalue);
+int parse_cpu_set_and_warn(const char *rvalue, cpu_set_t **cpu_set, const char *unit, const char *filename, unsigned line, const char *lvalue);
 
 #define xsprintf(buf, fmt, ...) \
         assert_message_se((size_t) snprintf(buf, ELEMENTSOF(buf), fmt, __VA_ARGS__) < ELEMENTSOF(buf), \
index 7d6d46b904b5475d44ebeed575bc7a4dc58ffd8d..2d73ef49c8ad41d77b08aa6a7a6420afca0c8756 100644 (file)
@@ -860,8 +860,7 @@ int config_parse_exec_cpu_affinity(const char *unit,
         assert(rvalue);
         assert(data);
 
-        ncpus = parse_cpu_set(rvalue, &cpuset, unit, filename, line, lvalue);
-
+        ncpus = parse_cpu_set_and_warn(rvalue, &cpuset, unit, filename, line, lvalue);
         if (ncpus < 0)
                 return ncpus;
 
index a244cbb3d5ba9943d455e05777ee17f3c32cdb37..ee6576fb35e3e07ea0aaf7f34cc1b1f675aec765 100644 (file)
@@ -464,8 +464,7 @@ static int config_parse_cpu_affinity2(
         _cleanup_cpu_free_ cpu_set_t *c = NULL;
         int ncpus;
 
-        ncpus = parse_cpu_set(rvalue, &c, unit, filename, line, lvalue);
-
+        ncpus = parse_cpu_set_and_warn(rvalue, &c, unit, filename, line, lvalue);
         if (ncpus < 0)
                 return ncpus;
 
index f434c5ceba86d0662948f93f35e9e92569a33251..70c125172942fddd831c31fcdfd9badaf492e2a7 100644 (file)
@@ -966,7 +966,7 @@ static void test_parse_cpu_set(void) {
         int cpu;
 
         /* Simple range (from CPUAffinity example) */
-        ncpus = parse_cpu_set("1 2", &c, NULL, "fake", 1, "CPUAffinity");
+        ncpus = parse_cpu_set_and_warn("1 2", &c, NULL, "fake", 1, "CPUAffinity");
         assert_se(ncpus >= 1024);
         assert_se(CPU_ISSET_S(1, CPU_ALLOC_SIZE(ncpus), c));
         assert_se(CPU_ISSET_S(2, CPU_ALLOC_SIZE(ncpus), c));
@@ -974,7 +974,7 @@ static void test_parse_cpu_set(void) {
         c = mfree(c);
 
         /* A more interesting range */
-        ncpus = parse_cpu_set("0 1 2 3 8 9 10 11", &c, NULL, "fake", 1, "CPUAffinity");
+        ncpus = parse_cpu_set_and_warn("0 1 2 3 8 9 10 11", &c, NULL, "fake", 1, "CPUAffinity");
         assert_se(ncpus >= 1024);
         assert_se(CPU_COUNT_S(CPU_ALLOC_SIZE(ncpus), c) == 8);
         for (cpu = 0; cpu < 4; cpu++)
@@ -984,7 +984,7 @@ static void test_parse_cpu_set(void) {
         c = mfree(c);
 
         /* Quoted strings */
-        ncpus = parse_cpu_set("8 '9' 10 \"11\"", &c, NULL, "fake", 1, "CPUAffinity");
+        ncpus = parse_cpu_set_and_warn("8 '9' 10 \"11\"", &c, NULL, "fake", 1, "CPUAffinity");
         assert_se(ncpus >= 1024);
         assert_se(CPU_COUNT_S(CPU_ALLOC_SIZE(ncpus), c) == 4);
         for (cpu = 8; cpu < 12; cpu++)
@@ -992,28 +992,28 @@ static void test_parse_cpu_set(void) {
         c = mfree(c);
 
         /* Use commas as separators */
-        ncpus = parse_cpu_set("0,1,2,3 8,9,10,11", &c, NULL, "fake", 1, "CPUAffinity");
+        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);
 
         /* Ranges */
-        ncpus = parse_cpu_set("0-3,8-11", &c, NULL, "fake", 1, "CPUAffinity");
+        ncpus = parse_cpu_set_and_warn("0-3,8-11", &c, NULL, "fake", 1, "CPUAffinity");
         assert_se(ncpus < 0);
         assert_se(!c);
 
         /* Garbage */
-        ncpus = parse_cpu_set("0 1 2 3 garbage", &c, NULL, "fake", 1, "CPUAffinity");
+        ncpus = parse_cpu_set_and_warn("0 1 2 3 garbage", &c, NULL, "fake", 1, "CPUAffinity");
         assert_se(ncpus < 0);
         assert_se(!c);
 
         /* Empty string */
         c = NULL;
-        ncpus = parse_cpu_set("", &c, NULL, "fake", 1, "CPUAffinity");
+        ncpus = parse_cpu_set_and_warn("", &c, NULL, "fake", 1, "CPUAffinity");
         assert_se(ncpus == 0);  /* empty string returns 0 */
         assert_se(!c);
 
         /* Runnaway quoted string */
-        ncpus = parse_cpu_set("0 1 2 3 \"4 5 6 7 ", &c, NULL, "fake", 1, "CPUAffinity");
+        ncpus = parse_cpu_set_and_warn("0 1 2 3 \"4 5 6 7 ", &c, NULL, "fake", 1, "CPUAffinity");
         assert_se(ncpus < 0);
         assert_se(!c);
 }