]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util: Declare a cleanup routine for a cpu_set_t
authorFilipe Brandenburger <filbranden@google.com>
Mon, 31 Aug 2015 03:46:27 +0000 (20:46 -0700)
committerFilipe Brandenburger <filbranden@google.com>
Tue, 1 Sep 2015 00:15:56 +0000 (17:15 -0700)
Make use of it in config_parse_cpu_affinity2.

Tested by tweaking the `CPUAffinity' setting in /etc/systemd/system.conf
and reloading the daemon to confirm it is working as expected.

No regressions observed in test cases.

src/basic/util.h
src/core/main.c

index 1484ef58e53c39f3658b12cdcf0bbad27c741df7..ff7a00e928a313ba59510d736aa43b45346784e4 100644 (file)
@@ -363,6 +363,9 @@ int fd_is_temporary_fs(int fd);
 
 int pipe_eof(int fd);
 
+DEFINE_TRIVIAL_CLEANUP_FUNC(cpu_set_t*, CPU_FREE);
+#define _cleanup_cpu_free_ _cleanup_(CPU_FREEp)
+
 cpu_set_t* cpu_set_malloc(unsigned *ncpus);
 
 #define xsprintf(buf, fmt, ...) assert_se((size_t) snprintf(buf, ELEMENTSOF(buf), fmt, __VA_ARGS__) < ELEMENTSOF(buf))
index 9c2b0c0897a5ecda119433d2552dac439e562852..539c57a7b8a2d933f6996c45ae293e1de72198c4 100644 (file)
@@ -433,7 +433,7 @@ static int config_parse_cpu_affinity2(
                 void *data,
                 void *userdata) {
 
-        cpu_set_t *c = NULL;
+        _cleanup_cpu_free_ cpu_set_t *c = NULL;
         unsigned ncpus = 0;
 
         assert(filename);
@@ -460,7 +460,6 @@ static int config_parse_cpu_affinity2(
                 if (r < 0 || cpu >= ncpus) {
                         log_syntax(unit, LOG_ERR, filename, line, -r,
                                    "Failed to parse CPU affinity '%s'", rvalue);
-                        CPU_FREE(c);
                         return -EBADMSG;
                 }
 
@@ -470,13 +469,10 @@ static int config_parse_cpu_affinity2(
                 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
                            "Trailing garbage, ignoring.");
 
-        if (c) {
+        if (c)
                 if (sched_setaffinity(0, CPU_ALLOC_SIZE(ncpus), c) < 0)
                         log_warning("Failed to set CPU affinity: %m");
 
-                CPU_FREE(c);
-        }
-
         return 0;
 }