chiark / gitweb /
bus: don't switch to kdbus if not requested
authorDavid Herrmann <dh.herrmann@gmail.com>
Wed, 6 May 2015 16:18:43 +0000 (18:18 +0200)
committerSven Eden <yamakuzure@gmx.net>
Tue, 14 Mar 2017 07:22:33 +0000 (08:22 +0100)
Whenever systemd is re-executed, it tries to create a system bus via
kdbus. If the system did not have kdbus loaded during bootup, but the
module is loaded later on manually, this will cause two system buses
running (kdbus and dbus-daemon in parallel).

This patch makes sure we never try to create kdbus buses if it wasn't
explicitly requested on the command-line.

src/libelogind/sd-bus/bus-util.c
src/libelogind/sd-bus/bus-util.h

index 32a17c6ea4af31812c0a5fd137f86415048e978b..a826fe2b87f057db8a99afe1adc3d6ac99483a39 100644 (file)
@@ -2041,3 +2041,30 @@ int bus_path_decode_unique(const char *path, const char *prefix, char **ret_send
         *ret_external = external;
         return 1;
 }
+
+bool is_kdbus_wanted(void) {
+        _cleanup_free_ char *value = NULL;
+        int r;
+
+        if (get_proc_cmdline_key("kdbus", NULL) <= 0) {
+                r = get_proc_cmdline_key("kdbus=", &value);
+                if (r <= 0 || parse_boolean(value) != 1)
+                        return false;
+        }
+
+        return true;
+}
+
+bool is_kdbus_available(void) {
+        _cleanup_close_ int fd = -1;
+        struct kdbus_cmd cmd = { .size = sizeof(cmd), .flags = KDBUS_FLAG_NEGOTIATE };
+
+        if (!is_kdbus_wanted())
+                return false;
+
+        fd = open("/sys/fs/kdbus/control", O_RDWR | O_CLOEXEC | O_NONBLOCK | O_NOCTTY);
+        if (fd < 0)
+                return false;
+
+        return ioctl(fd, KDBUS_CMD_BUS_MAKE, &cmd) >= 0;
+}
index 6216a2c8b06bcc8f811134785b0ffe76928bb5a0..0594cda5fcc33ced150d79c7d4520f116962a876 100644 (file)
@@ -204,3 +204,6 @@ int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet);
 
 int bus_path_encode_unique(sd_bus *b, const char *prefix, const char *sender_id, const char *external_id, char **ret_path);
 int bus_path_decode_unique(const char *path, const char *prefix, char **ret_sender, char **ret_external);
+
+bool is_kdbus_wanted(void);
+bool is_kdbus_available(void);