[systemd-commits] src/core src/dbus1-generator src/libsystemd
David Herrmann
dvdhrm at kemper.freedesktop.org
Wed May 6 09:22:18 PDT 2015
src/core/busname.c | 2 +-
src/core/kmod-setup.c | 7 ++-----
src/core/manager.c | 2 ++
src/dbus1-generator/dbus1-generator.c | 4 ++--
src/libsystemd/sd-bus/bus-util.c | 27 +++++++++++++++++++++++++++
src/libsystemd/sd-bus/bus-util.h | 3 +++
6 files changed, 37 insertions(+), 8 deletions(-)
New commits:
commit d79acc309327f8c0863bd3da8b93d926a1c93ba1
Author: David Herrmann <dh.herrmann at gmail.com>
Date: Wed May 6 18:18:43 2015 +0200
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.
diff --git a/src/core/busname.c b/src/core/busname.c
index 1278c96..3dc6e87 100644
--- a/src/core/busname.c
+++ b/src/core/busname.c
@@ -988,7 +988,7 @@ static bool busname_supported(void) {
static int supported = -1;
if (supported < 0)
- supported = access("/sys/fs/kdbus", F_OK) >= 0;
+ supported = is_kdbus_available();
return supported;
}
diff --git a/src/core/kmod-setup.c b/src/core/kmod-setup.c
index c5117b4..132c3e8 100644
--- a/src/core/kmod-setup.c
+++ b/src/core/kmod-setup.c
@@ -28,6 +28,7 @@
#include "macro.h"
#include "capability.h"
+#include "bus-util.h"
#include "kmod-setup.h"
#ifdef HAVE_KMOD
@@ -44,10 +45,6 @@ static void systemd_kmod_log(
log_internalv(LOG_DEBUG, 0, file, line, fn, format, args);
REENABLE_WARNING;
}
-
-static bool cmdline_check_kdbus(void) {
- return get_proc_cmdline_key("kdbus", NULL) > 0;
-}
#endif
int kmod_setup(void) {
@@ -69,7 +66,7 @@ int kmod_setup(void) {
{ "unix", "/proc/net/unix", true, NULL },
/* IPC is needed before we bring up any other services */
- { "kdbus", "/sys/fs/kdbus", false, cmdline_check_kdbus },
+ { "kdbus", "/sys/fs/kdbus", false, is_kdbus_wanted },
/* netfilter is needed by networkd, nspawn among others, and cannot be autoloaded */
{ "ip_tables", "/proc/net/ip_tables_names", false, NULL },
diff --git a/src/core/manager.c b/src/core/manager.c
index 8c8645b..c918f19 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -721,6 +721,8 @@ static int manager_setup_kdbus(Manager *m) {
if (m->test_run || m->kdbus_fd >= 0)
return 0;
+ if (!is_kdbus_available())
+ return -ESOCKTNOSUPPORT;
if (m->running_as == SYSTEMD_SYSTEM && detect_container(NULL) <= 0)
bus_kernel_fix_attach_mask();
diff --git a/src/dbus1-generator/dbus1-generator.c b/src/dbus1-generator/dbus1-generator.c
index c909a4b..4980fcc 100644
--- a/src/dbus1-generator/dbus1-generator.c
+++ b/src/dbus1-generator/dbus1-generator.c
@@ -302,7 +302,7 @@ int main(int argc, char *argv[]) {
umask(0022);
- if (access("/sys/fs/kdbus/control", F_OK) < 0)
+ if (!is_kdbus_available())
return 0;
r = cg_pid_get_owner_uid(0, NULL);
@@ -310,7 +310,7 @@ int main(int argc, char *argv[]) {
path = "/usr/share/dbus-1/services";
type = "session";
units = USER_DATA_UNIT_PATH;
- } else if (r == -ENOENT) {
+ } else if (r == -ENXIO) {
path = "/usr/share/dbus-1/system-services";
type = "system";
units = SYSTEM_DATA_UNIT_PATH;
diff --git a/src/libsystemd/sd-bus/bus-util.c b/src/libsystemd/sd-bus/bus-util.c
index f0695bf..7536a96 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 d3a18e2..093b48b 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);
More information about the systemd-commits
mailing list