daandemeyer / rpms / systemd

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