chiark / gitweb /
util: split out signal-util.[ch] from util.[ch]
[elogind.git] / src / libelogind / sd-bus / bus-util.c
index 32a17c6ea4af31812c0a5fd137f86415048e978b..96296aa1c1fabf4f12ebb6499b5df7f5f131fbf5 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"
@@ -1889,7 +1890,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 +1905,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 +2046,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;
+}