chiark / gitweb /
kdbus: set kernel attach mask before creating the first bus
authorLennart Poettering <lennart@poettering.net>
Thu, 27 Nov 2014 20:28:13 +0000 (21:28 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 27 Nov 2014 21:05:24 +0000 (22:05 +0100)
src/core/manager.c
src/libsystemd/sd-bus/bus-kernel.c
src/libsystemd/sd-bus/bus-kernel.h
src/libsystemd/sd-bus/test-bus-kernel.c
src/shared/util.c
src/shared/util.h

index 7af502a..0d1f5bb 100644 (file)
@@ -722,7 +722,12 @@ static int manager_setup_kdbus(Manager *m) {
         if (m->test_run || m->kdbus_fd >= 0)
                 return 0;
 
-        m->kdbus_fd = bus_kernel_create_bus(m->running_as == SYSTEMD_SYSTEM ? "system" : "user", m->running_as == SYSTEMD_SYSTEM, &p);
+        bus_kernel_fix_attach_mask();
+
+        m->kdbus_fd = bus_kernel_create_bus(
+                        m->running_as == SYSTEMD_SYSTEM ? "system" : "user",
+                        m->running_as == SYSTEMD_SYSTEM, &p);
+
         if (m->kdbus_fd < 0) {
                 log_debug("Failed to set up kdbus: %s", strerror(-m->kdbus_fd));
                 return m->kdbus_fd;
index 3bf7b07..759d566 100644 (file)
@@ -32,6 +32,8 @@
 #include "util.h"
 #include "strv.h"
 #include "memfd-util.h"
+#include "cgroup-util.h"
+#include "fileio.h"
 
 #include "bus-internal.h"
 #include "bus-message.h"
@@ -39,7 +41,6 @@
 #include "bus-bloom.h"
 #include "bus-util.h"
 #include "bus-label.h"
-#include "cgroup-util.h"
 
 #define UNIQUE_NAME_MAX (3+DECIMAL_STR_MAX(uint64_t))
 
@@ -1796,3 +1797,35 @@ int bus_kernel_realize_attach_flags(sd_bus *bus) {
 
         return 0;
 }
+
+int bus_kernel_fix_attach_mask(void) {
+        _cleanup_free_ char *mask = NULL;
+        uint64_t m = (uint32_t) -1;
+        char buf[2+16+2];
+        int r;
+
+        r = get_proc_cmdline_key("systemd.kdbus_attach_flags_mask=", &mask);
+        if (r < 0) {
+                log_warning_errno(-r, "Failed to read kernel command line: %m");
+                return r;
+        }
+
+        if (mask) {
+                const char *p = mask;
+
+                if (startswith(p, "0x"))
+                        p += 2;
+
+                if (sscanf(p, "%" PRIx64, &m) != 1)
+                        log_warning("Couldn't parse systemd.kdbus_attach_flags_mask= kernel command line parameter.");
+        }
+
+        sprintf(buf, "0x%" PRIx64 "\n", m);
+        r = write_string_file("/sys/module/kdbus/parameters/attach_flags_mask", buf);
+        if (r < 0) {
+                log_warning_errno(-r, "Failed to write kdbus attach mask: %m");
+                return r;
+        }
+
+        return 0;
+}
index 8994b35..0db8fd3 100644 (file)
@@ -89,3 +89,5 @@ int bus_kernel_try_close(sd_bus *bus);
 int bus_kernel_drop_one(int fd);
 
 int bus_kernel_realize_attach_flags(sd_bus *bus);
+
+int bus_kernel_fix_attach_mask(void);
index 0e6c2ac..485c396 100644 (file)
@@ -45,6 +45,8 @@ int main(int argc, char *argv[]) {
 
         assert_se(asprintf(&name, "deine-mutter-%u", (unsigned) getpid()) >= 0);
 
+        bus_kernel_fix_attach_mask();
+
         bus_ref = bus_kernel_create_bus(name, false, &bus_name);
         if (bus_ref == -ENOENT)
                 return EXIT_TEST_SKIP;
index e987abc..d3eec5f 100644 (file)
@@ -6270,38 +6270,16 @@ int split_pair(const char *s, const char *sep, char **l, char **r) {
 }
 
 int shall_restore_state(void) {
-        _cleanup_free_ char *line = NULL;
-        const char *p;
+        _cleanup_free_ char *value = NULL;
         int r;
 
-        r = proc_cmdline(&line);
+        r = get_proc_cmdline_key("systemd.restore_state=", &value);
         if (r < 0)
                 return r;
+        if (r == 0)
+                return true;
 
-        r = 1;
-        p = line;
-
-        for (;;) {
-                _cleanup_free_ char *word = NULL;
-                const char *e;
-                int k;
-
-                k = unquote_first_word(&p, &word, true);
-                if (k < 0)
-                        return k;
-                if (k == 0)
-                        break;
-
-                e = startswith(word, "systemd.restore_state=");
-                if (!e)
-                        continue;
-
-                k = parse_boolean(e);
-                if (k >= 0)
-                        r = k;
-        }
-
-        return r;
+        return parse_boolean(value) != 0;
 }
 
 int proc_cmdline(char **ret) {
@@ -6352,6 +6330,59 @@ int parse_proc_cmdline(int (*parse_item)(const char *key, const char *value)) {
         return 0;
 }
 
+int get_proc_cmdline_key(const char *key, char **value) {
+        _cleanup_free_ char *line = NULL, *ret = NULL;
+        bool found = false;
+        const char *p;
+        int r;
+
+        assert(key);
+
+        r = proc_cmdline(&line);
+        if (r < 0)
+                return r;
+
+        p = line;
+        for (;;) {
+                _cleanup_free_ char *word = NULL;
+                const char *e;
+
+                r = unquote_first_word(&p, &word, true);
+                if (r < 0)
+                        return r;
+                if (r == 0)
+                        break;
+
+                /* Filter out arguments that are intended only for the
+                 * initrd */
+                if (!in_initrd() && startswith(word, "rd."))
+                        continue;
+
+                if (value) {
+                        e = startswith(word, key);
+                        if (!e)
+                                continue;
+
+                        r = free_and_strdup(&ret, e);
+                        if (r < 0)
+                                return r;
+
+                        found = true;
+                } else {
+                        if (streq(word, key))
+                                found = true;
+                }
+        }
+
+        if (value) {
+                *value = ret;
+                ret = NULL;
+        }
+
+        return found;
+
+}
+
 int container_get_leader(const char *machine, pid_t *pid) {
         _cleanup_free_ char *s = NULL, *class = NULL;
         const char *p;
index d36a632..13da942 100644 (file)
@@ -972,6 +972,7 @@ static inline void qsort_safe(void *base, size_t nmemb, size_t size,
 
 int proc_cmdline(char **ret);
 int parse_proc_cmdline(int (*parse_word)(const char *key, const char *value));
+int get_proc_cmdline_key(const char *parameter, char **value);
 
 int container_get_leader(const char *machine, pid_t *pid);