X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=dbus.c;h=6ed659a2393e870786035e71f22b05b193f85c36;hb=4f4a1dbf2171aa62da04d2e3b6945e8992139d14;hp=a1a3606361eb8654efb67ef2ffed09343b1ab6ad;hpb=05e343b70453716cc6292b17e7ef175a8c106aad;p=elogind.git
diff --git a/dbus.c b/dbus.c
index a1a360636..6ed659a23 100644
--- a/dbus.c
+++ b/dbus.c
@@ -19,17 +19,19 @@
along with systemd; If not, see .
***/
-#include
-
#include
#include
#include
#include
+#include
#include "dbus.h"
#include "log.h"
#include "strv.h"
#include "cgroup.h"
+#include "dbus-unit.h"
+#include "dbus-job.h"
+#include "dbus-manager.h"
static void api_bus_dispatch_status(DBusConnection *bus, DBusDispatchStatus status, void *data) {
Manager *m = data;
@@ -379,6 +381,18 @@ static DBusHandlerResult system_bus_message_filter(DBusConnection *connection,
unsigned bus_dispatch(Manager *m) {
assert(m);
+ if (m->queued_message) {
+ /* If we cannot get rid of this message we won't
+ * dispatch any D-Bus messages, so that we won't end
+ * up wanting to queue another message. */
+
+ if (!dbus_connection_send(m->api_bus, m->queued_message, NULL))
+ return 0;
+
+ dbus_message_unref(m->queued_message);
+ m->queued_message = NULL;
+ }
+
if (m->request_api_bus_dispatch) {
if (dbus_connection_dispatch(m->api_bus) == DBUS_DISPATCH_COMPLETE)
m->request_api_bus_dispatch = false;
@@ -635,6 +649,7 @@ void bus_done_api(Manager *m) {
m->system_bus = NULL;
dbus_connection_set_dispatch_status_function(m->api_bus, NULL, NULL, NULL);
+ dbus_connection_flush(m->api_bus);
dbus_connection_close(m->api_bus);
dbus_connection_unref(m->api_bus);
m->api_bus = NULL;
@@ -652,6 +667,11 @@ void bus_done_api(Manager *m) {
if (m->name_data_slot >= 0)
dbus_pending_call_free_data_slot(&m->name_data_slot);
+
+ if (m->queued_message) {
+ dbus_message_unref(m->queued_message);
+ m->queued_message = NULL;
+ }
}
void bus_done_system(Manager *m) {
@@ -662,6 +682,7 @@ void bus_done_system(Manager *m) {
if (m->system_bus) {
dbus_connection_set_dispatch_status_function(m->system_bus, NULL, NULL, NULL);
+ dbus_connection_flush(m->system_bus);
dbus_connection_close(m->system_bus);
dbus_connection_unref(m->system_bus);
m->system_bus = NULL;
@@ -1023,6 +1044,10 @@ int bus_property_append_uint64(Manager *m, DBusMessageIter *i, const char *prope
assert(property);
assert(data);
+ /* Let's ensure that pid_t is actually 64bit, and hence this
+ * function can be used for usec_t */
+ assert_cc(sizeof(uint64_t) == sizeof(usec_t));
+
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, data))
return -ENOMEM;
@@ -1035,8 +1060,77 @@ int bus_property_append_uint32(Manager *m, DBusMessageIter *i, const char *prope
assert(property);
assert(data);
+ /* Let's ensure that pid_t and mode_t is actually 32bit, and
+ * hence this function can be used for pid_t/mode_t */
+ assert_cc(sizeof(uint32_t) == sizeof(pid_t));
+ assert_cc(sizeof(uint32_t) == sizeof(mode_t));
+ assert_cc(sizeof(uint32_t) == sizeof(unsigned));
+
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT32, data))
return -ENOMEM;
return 0;
}
+
+int bus_property_append_int32(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+ assert(m);
+ assert(i);
+ assert(property);
+ assert(data);
+
+ assert_cc(sizeof(int32_t) == sizeof(int));
+
+ if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, data))
+ return -ENOMEM;
+
+ return 0;
+}
+
+int bus_parse_strv(DBusMessage *m, char ***_l) {
+ DBusMessageIter iter, sub;
+ unsigned n = 0, i = 0;
+ char **l;
+
+ assert(m);
+ assert(_l);
+
+ if (!dbus_message_iter_init(m, &iter) ||
+ dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
+ dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_STRING)
+ return -EINVAL;
+
+ dbus_message_iter_recurse(&iter, &sub);
+
+ while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
+ n++;
+ dbus_message_iter_next(&sub);
+ }
+
+ if (!(l = new(char*, n+1)))
+ return -ENOMEM;
+
+ assert_se(dbus_message_iter_init(m, &iter));
+ dbus_message_iter_recurse(&iter, &sub);
+
+ while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
+ const char *s;
+
+ assert_se(dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_STRING);
+ dbus_message_iter_get_basic(&sub, &s);
+
+ if (!(l[i++] = strdup(s))) {
+ strv_free(l);
+ return -ENOMEM;
+ }
+
+ dbus_message_iter_next(&sub);
+ }
+
+ assert(i == n);
+ l[i] = NULL;
+
+ if (_l)
+ *_l = l;
+
+ return 0;
+}