4fbe94
From fb1244ef318e9f54628a7c13db9e2ffbc712dd38 Mon Sep 17 00:00:00 2001
4fbe94
From: Michal Sekletar <msekleta@redhat.com>
4fbe94
Date: Wed, 22 May 2019 17:14:21 +0200
4fbe94
Subject: [PATCH] systemctl: present CPUAffinity mask as a list of CPU index
4fbe94
 ranges
4fbe94
4fbe94
(cherry picked from commit a047f4f10ed2f922d6079c033d24a443b0e95f38)
4fbe94
4fbe94
Related: #1734787
4fbe94
---
4fbe94
 src/systemctl/systemctl.c | 22 ++++++++++++++++++++++
4fbe94
 1 file changed, 22 insertions(+)
4fbe94
4fbe94
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
4fbe94
index f072ad0c31..0154b300a3 100644
4fbe94
--- a/src/systemctl/systemctl.c
4fbe94
+++ b/src/systemctl/systemctl.c
4fbe94
@@ -30,6 +30,7 @@
4fbe94
 #include "cgroup-show.h"
4fbe94
 #include "cgroup-util.h"
4fbe94
 #include "copy.h"
4fbe94
+#include "cpu-set-util.h"
4fbe94
 #include "dropin.h"
4fbe94
 #include "efivars.h"
4fbe94
 #include "env-util.h"
4fbe94
@@ -4876,6 +4877,27 @@ static int print_property(const char *name, sd_bus_message *m, bool value, bool
4fbe94
 
4fbe94
                         print_prop(name, "%s", h);
4fbe94
 
4fbe94
+                        return 1;
4fbe94
+                } else if (contents[0] == SD_BUS_TYPE_BYTE && streq(name, "CPUAffinity")) {
4fbe94
+                        _cleanup_free_ char *affinity = NULL;
4fbe94
+                        _cleanup_(cpu_set_reset) CPUSet set = {};
4fbe94
+                        const void *a;
4fbe94
+                        size_t n;
4fbe94
+
4fbe94
+                        r = sd_bus_message_read_array(m, 'y', &a, &n);
4fbe94
+                        if (r < 0)
4fbe94
+                                return bus_log_parse_error(r);
4fbe94
+
4fbe94
+                        r = cpu_set_from_dbus(a, n, &set);
4fbe94
+                        if (r < 0)
4fbe94
+                                return log_error_errno(r, "Failed to deserialize CPUAffinity: %m");
4fbe94
+
4fbe94
+                        affinity = cpu_set_to_range_string(&set);
4fbe94
+                        if (!affinity)
4fbe94
+                                return log_oom();
4fbe94
+
4fbe94
+                        print_prop(name, "%s", affinity);
4fbe94
+
4fbe94
                         return 1;
4fbe94
                 }
4fbe94