chiark / gitweb /
sd-bus: fix marshaling of unary type
[elogind.git] / src / libelogind / sd-bus / bus-util.c
index 32a17c6ea4af31812c0a5fd137f86415048e978b..2e4cd572fe78ca175374a165ac1e6b283f405dd5 100644 (file)
@@ -30,6 +30,7 @@
 #include "path-util.h"
 #include "missing.h"
 #include "set.h"
+#include "signal-util.h"
 #include "unit-name.h"
 
 #include "sd-bus.h"
@@ -544,7 +545,6 @@ int bus_open_system_systemd(sd_bus **_bus) {
          * directly to the system instance, instead of going via the
          * bus */
 
-#ifdef ENABLE_KDBUS
         r = sd_bus_new(&bus);
         if (r < 0)
                 return r;
@@ -563,7 +563,6 @@ int bus_open_system_systemd(sd_bus **_bus) {
         }
 
         bus = sd_bus_unref(bus);
-#endif
 
         r = sd_bus_new(&bus);
         if (r < 0)
@@ -597,7 +596,6 @@ int bus_open_user_systemd(sd_bus **_bus) {
 
         assert(_bus);
 
-#ifdef ENABLE_KDBUS
         r = sd_bus_new(&bus);
         if (r < 0)
                 return r;
@@ -615,7 +613,6 @@ int bus_open_user_systemd(sd_bus **_bus) {
         }
 
         bus = sd_bus_unref(bus);
-#endif
 
         e = secure_getenv("XDG_RUNTIME_DIR");
         if (!e)
@@ -1889,7 +1886,7 @@ int bus_wait_for_jobs_add(BusWaitForJobs *d, const char *path) {
         return set_put_strdup(d->jobs, path);
 }
 
-int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet) {
+int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, UnitFileChange **changes, unsigned *n_changes) {
         const char *type, *path, *source;
         int r;
 
@@ -1904,6 +1901,10 @@ int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet) {
                         else
                                 log_info("Removed symlink %s.", path);
                 }
+
+                r = unit_file_changes_add(changes, n_changes, streq(type, "symlink") ? UNIT_FILE_SYMLINK : UNIT_FILE_UNLINK, path, source);
+                if (r < 0)
+                        return r;
         }
         if (r < 0)
                 return bus_log_parse_error(r);
@@ -2041,3 +2042,37 @@ 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;
+#ifdef ENABLE_KDBUS
+        const bool configured = true;
+#else
+        const bool configured = false;
+#endif
+
+        int r;
+
+        if (get_proc_cmdline_key("kdbus", NULL) > 0)
+                return true;
+
+        r = get_proc_cmdline_key("kdbus=", &value);
+        if (r <= 0)
+                return configured;
+
+        return parse_boolean(value) == 1;
+}
+
+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;
+}