richardphibel / rpms / systemd

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