diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2015-05-06 18:18:43 +0200 |
---|---|---|
committer | David Herrmann <dh.herrmann@gmail.com> | 2015-05-06 18:21:51 +0200 |
commit | d79acc309327f8c0863bd3da8b93d926a1c93ba1 (patch) | |
tree | 563a1eb14323f7346bdd0378481c300d6ea9c4ce /src/libsystemd | |
parent | f2bf5007a97bf5993128a6e16105005f819b60cf (diff) |
bus: don't switch to kdbus if not requested
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.
Diffstat (limited to 'src/libsystemd')
-rw-r--r-- | src/libsystemd/sd-bus/bus-util.c | 27 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/bus-util.h | 3 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src/libsystemd/sd-bus/bus-util.c b/src/libsystemd/sd-bus/bus-util.c index f0695bfde0..7536a96b8d 100644 --- a/src/libsystemd/sd-bus/bus-util.c +++ b/src/libsystemd/sd-bus/bus-util.c @@ -2051,3 +2051,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; +} diff --git a/src/libsystemd/sd-bus/bus-util.h b/src/libsystemd/sd-bus/bus-util.h index d3a18e2d94..093b48b8f8 100644 --- a/src/libsystemd/sd-bus/bus-util.h +++ b/src/libsystemd/sd-bus/bus-util.h @@ -205,3 +205,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); |