1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include <sys/epoll.h>
23 #include <sys/timerfd.h>
26 #include <dbus/dbus.h>
32 #include "dbus-unit.h"
34 #include "dbus-manager.h"
35 #include "dbus-service.h"
36 #include "dbus-socket.h"
37 #include "dbus-target.h"
38 #include "dbus-device.h"
39 #include "dbus-mount.h"
40 #include "dbus-automount.h"
41 #include "dbus-snapshot.h"
42 #include "dbus-swap.h"
43 #include "dbus-timer.h"
44 #include "dbus-path.h"
46 static const char bus_properties_interface[] = BUS_PROPERTIES_INTERFACE;
47 static const char bus_introspectable_interface[] = BUS_INTROSPECTABLE_INTERFACE;
49 const char *const bus_interface_table[] = {
50 "org.freedesktop.DBus.Properties", bus_properties_interface,
51 "org.freedesktop.DBus.Introspectable", bus_introspectable_interface,
52 "org.freedesktop.systemd1.Manager", bus_manager_interface,
53 "org.freedesktop.systemd1.Job", bus_job_interface,
54 "org.freedesktop.systemd1.Unit", bus_unit_interface,
55 "org.freedesktop.systemd1.Service", bus_service_interface,
56 "org.freedesktop.systemd1.Socket", bus_socket_interface,
57 "org.freedesktop.systemd1.Target", bus_target_interface,
58 "org.freedesktop.systemd1.Device", bus_device_interface,
59 "org.freedesktop.systemd1.Mount", bus_mount_interface,
60 "org.freedesktop.systemd1.Automount", bus_automount_interface,
61 "org.freedesktop.systemd1.Snapshot", bus_snapshot_interface,
62 "org.freedesktop.systemd1.Swap", bus_swap_interface,
63 "org.freedesktop.systemd1.Timer", bus_timer_interface,
64 "org.freedesktop.systemd1.Path", bus_path_interface,
68 static void api_bus_dispatch_status(DBusConnection *bus, DBusDispatchStatus status, void *data) {
77 assert(m->api_bus == bus);
79 m->request_api_bus_dispatch = status != DBUS_DISPATCH_COMPLETE;
82 static void system_bus_dispatch_status(DBusConnection *bus, DBusDispatchStatus status, void *data) {
91 assert(m->system_bus == bus);
93 m->request_system_bus_dispatch = status != DBUS_DISPATCH_COMPLETE;
96 static uint32_t bus_flags_to_events(DBusWatch *bus_watch) {
102 /* no watch flags for disabled watches */
103 if (!dbus_watch_get_enabled(bus_watch))
106 flags = dbus_watch_get_flags(bus_watch);
108 if (flags & DBUS_WATCH_READABLE)
110 if (flags & DBUS_WATCH_WRITABLE)
113 return events | EPOLLHUP | EPOLLERR;
116 static unsigned events_to_bus_flags(uint32_t events) {
119 if (events & EPOLLIN)
120 flags |= DBUS_WATCH_READABLE;
121 if (events & EPOLLOUT)
122 flags |= DBUS_WATCH_WRITABLE;
123 if (events & EPOLLHUP)
124 flags |= DBUS_WATCH_HANGUP;
125 if (events & EPOLLERR)
126 flags |= DBUS_WATCH_ERROR;
131 void bus_watch_event(Manager *m, Watch *w, int events) {
135 /* This is called by the event loop whenever there is
136 * something happening on D-Bus' file handles. */
138 if (!dbus_watch_get_enabled(w->data.bus_watch))
141 dbus_watch_handle(w->data.bus_watch, events_to_bus_flags(events));
144 static dbus_bool_t bus_add_watch(DBusWatch *bus_watch, void *data) {
147 struct epoll_event ev;
152 if (!(w = new0(Watch, 1)))
155 w->fd = dbus_watch_get_unix_fd(bus_watch);
156 w->type = WATCH_DBUS_WATCH;
157 w->data.bus_watch = bus_watch;
160 ev.events = bus_flags_to_events(bus_watch);
163 if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, w->fd, &ev) < 0) {
165 if (errno != EEXIST) {
170 /* Hmm, bloody D-Bus creates multiple watches on the
171 * same fd. epoll() does not like that. As a dirty
172 * hack we simply dup() the fd and hence get a second
173 * one we can safely add to the epoll(). */
175 if ((w->fd = dup(w->fd)) < 0) {
180 if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, w->fd, &ev) < 0) {
182 close_nointr_nofail(w->fd);
186 w->fd_is_dupped = true;
189 dbus_watch_set_data(bus_watch, w, NULL);
194 static void bus_remove_watch(DBusWatch *bus_watch, void *data) {
201 if (!(w = dbus_watch_get_data(bus_watch)))
204 assert(w->type == WATCH_DBUS_WATCH);
205 assert_se(epoll_ctl(m->epoll_fd, EPOLL_CTL_DEL, w->fd, NULL) >= 0);
208 close_nointr_nofail(w->fd);
213 static void bus_toggle_watch(DBusWatch *bus_watch, void *data) {
216 struct epoll_event ev;
221 assert_se(w = dbus_watch_get_data(bus_watch));
222 assert(w->type == WATCH_DBUS_WATCH);
225 ev.events = bus_flags_to_events(bus_watch);
228 assert_se(epoll_ctl(m->epoll_fd, EPOLL_CTL_MOD, w->fd, &ev) == 0);
231 static int bus_timeout_arm(Manager *m, Watch *w) {
232 struct itimerspec its;
239 if (dbus_timeout_get_enabled(w->data.bus_timeout)) {
240 timespec_store(&its.it_value, dbus_timeout_get_interval(w->data.bus_timeout) * USEC_PER_MSEC);
241 its.it_interval = its.it_interval;
244 if (timerfd_settime(w->fd, 0, &its, NULL) < 0)
250 void bus_timeout_event(Manager *m, Watch *w, int events) {
254 /* This is called by the event loop whenever there is
255 * something happening on D-Bus' file handles. */
257 if (!(dbus_timeout_get_enabled(w->data.bus_timeout)))
260 dbus_timeout_handle(w->data.bus_timeout);
263 static dbus_bool_t bus_add_timeout(DBusTimeout *timeout, void *data) {
266 struct epoll_event ev;
271 if (!(w = new0(Watch, 1)))
274 if (!(w->fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK|TFD_CLOEXEC)) < 0)
277 w->type = WATCH_DBUS_TIMEOUT;
278 w->data.bus_timeout = timeout;
280 if (bus_timeout_arm(m, w) < 0)
287 if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, w->fd, &ev) < 0)
290 dbus_timeout_set_data(timeout, w, NULL);
296 close_nointr_nofail(w->fd);
302 static void bus_remove_timeout(DBusTimeout *timeout, void *data) {
309 if (!(w = dbus_timeout_get_data(timeout)))
312 assert(w->type == WATCH_DBUS_TIMEOUT);
313 assert_se(epoll_ctl(m->epoll_fd, EPOLL_CTL_DEL, w->fd, NULL) >= 0);
314 close_nointr_nofail(w->fd);
318 static void bus_toggle_timeout(DBusTimeout *timeout, void *data) {
326 assert_se(w = dbus_timeout_get_data(timeout));
327 assert(w->type == WATCH_DBUS_TIMEOUT);
329 if ((r = bus_timeout_arm(m, w)) < 0)
330 log_error("Failed to rearm timer: %s", strerror(-r));
333 static DBusHandlerResult api_bus_message_filter(DBusConnection *connection, DBusMessage *message, void *data) {
341 dbus_error_init(&error);
343 /* log_debug("Got D-Bus request: %s.%s() on %s", */
344 /* dbus_message_get_interface(message), */
345 /* dbus_message_get_member(message), */
346 /* dbus_message_get_path(message)); */
348 if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected")) {
349 log_error("Warning! API D-Bus connection terminated.");
352 } else if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) {
353 const char *name, *old_owner, *new_owner;
355 if (!dbus_message_get_args(message, &error,
356 DBUS_TYPE_STRING, &name,
357 DBUS_TYPE_STRING, &old_owner,
358 DBUS_TYPE_STRING, &new_owner,
360 log_error("Failed to parse NameOwnerChanged message: %s", error.message);
362 if (set_remove(m->subscribed, (char*) name))
363 log_debug("Subscription client vanished: %s (left: %u)", name, set_size(m->subscribed));
365 if (old_owner[0] == 0)
368 if (new_owner[0] == 0)
371 manager_dispatch_bus_name_owner_changed(m, name, old_owner, new_owner);
375 dbus_error_free(&error);
376 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
379 static DBusHandlerResult system_bus_message_filter(DBusConnection *connection, DBusMessage *message, void *data) {
387 dbus_error_init(&error);
389 /* log_debug("Got D-Bus request: %s.%s() on %s", */
390 /* dbus_message_get_interface(message), */
391 /* dbus_message_get_member(message), */
392 /* dbus_message_get_path(message)); */
394 if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected")) {
395 log_error("Warning! System D-Bus connection terminated.");
398 } if (dbus_message_is_signal(message, "org.freedesktop.systemd1.Agent", "Released")) {
401 if (!dbus_message_get_args(message, &error,
402 DBUS_TYPE_STRING, &cgroup,
404 log_error("Failed to parse Released message: %s", error.message);
406 cgroup_notify_empty(m, cgroup);
409 dbus_error_free(&error);
410 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
413 unsigned bus_dispatch(Manager *m) {
416 if (m->queued_message) {
417 /* If we cannot get rid of this message we won't
418 * dispatch any D-Bus messages, so that we won't end
419 * up wanting to queue another message. */
421 if (!dbus_connection_send(m->api_bus, m->queued_message, NULL))
424 dbus_message_unref(m->queued_message);
425 m->queued_message = NULL;
428 if (m->request_api_bus_dispatch) {
429 if (dbus_connection_dispatch(m->api_bus) == DBUS_DISPATCH_COMPLETE)
430 m->request_api_bus_dispatch = false;
435 if (m->request_system_bus_dispatch) {
436 if (dbus_connection_dispatch(m->system_bus) == DBUS_DISPATCH_COMPLETE)
437 m->request_system_bus_dispatch = false;
445 static void request_name_pending_cb(DBusPendingCall *pending, void *userdata) {
449 dbus_error_init(&error);
451 assert_se(reply = dbus_pending_call_steal_reply(pending));
453 switch (dbus_message_get_type(reply)) {
455 case DBUS_MESSAGE_TYPE_ERROR:
457 assert_se(dbus_set_error_from_message(&error, reply));
458 log_warning("RequestName() failed: %s", error.message);
461 case DBUS_MESSAGE_TYPE_METHOD_RETURN: {
464 if (!dbus_message_get_args(reply,
466 DBUS_TYPE_UINT32, &r,
467 DBUS_TYPE_INVALID)) {
468 log_error("Failed to parse RequestName() reply: %s", error.message);
473 log_debug("Successfully acquired name.");
475 log_error("Name already owned.");
481 assert_not_reached("Invalid reply message");
484 dbus_message_unref(reply);
485 dbus_error_free(&error);
488 static int request_name(Manager *m) {
489 const char *name = "org.freedesktop.systemd1";
491 DBusMessage *message = NULL;
492 DBusPendingCall *pending = NULL;
494 if (!(message = dbus_message_new_method_call(
501 if (!dbus_message_append_args(
503 DBUS_TYPE_STRING, &name,
504 DBUS_TYPE_UINT32, &flags,
508 if (!dbus_connection_send_with_reply(m->api_bus, message, &pending, -1))
511 if (!dbus_pending_call_set_notify(pending, request_name_pending_cb, m, NULL))
514 dbus_message_unref(message);
515 dbus_pending_call_unref(pending);
517 /* We simple ask for the name and don't wait for it. Sooner or
518 * later we'll have it. */
524 dbus_pending_call_cancel(pending);
525 dbus_pending_call_unref(pending);
529 dbus_message_unref(message);
534 static int bus_setup_loop(Manager *m, DBusConnection *bus) {
538 dbus_connection_set_exit_on_disconnect(bus, FALSE);
540 if (!dbus_connection_set_watch_functions(bus, bus_add_watch, bus_remove_watch, bus_toggle_watch, m, NULL) ||
541 !dbus_connection_set_timeout_functions(bus, bus_add_timeout, bus_remove_timeout, bus_toggle_timeout, m, NULL))
547 int bus_init_system(Manager *m) {
554 dbus_error_init(&error);
559 if (m->running_as != MANAGER_SESSION && m->api_bus)
560 m->system_bus = m->api_bus;
562 if (!(m->system_bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error))) {
563 log_debug("Failed to get system D-Bus connection, retrying later: %s", error.message);
564 dbus_error_free(&error);
568 dbus_connection_set_dispatch_status_function(m->system_bus, system_bus_dispatch_status, m, NULL);
569 m->request_system_bus_dispatch = true;
571 if ((r = bus_setup_loop(m, m->system_bus)) < 0) {
577 if (!dbus_connection_add_filter(m->system_bus, system_bus_message_filter, m, NULL)) {
582 dbus_bus_add_match(m->system_bus,
584 "interface='org.freedesktop.systemd1.Agent',"
585 "path='/org/freedesktop/systemd1/agent'",
588 if (dbus_error_is_set(&error)) {
589 log_error("Failed to register match: %s", error.message);
590 dbus_error_free(&error);
595 log_debug("Successfully connected to system D-Bus bus %s as %s",
596 strnull((id = dbus_connection_get_server_id(m->system_bus))),
597 strnull(dbus_bus_get_unique_name(m->system_bus)));
603 int bus_init_api(Manager *m) {
610 dbus_error_init(&error);
615 if (m->name_data_slot < 0)
616 if (!dbus_pending_call_allocate_data_slot(&m->name_data_slot))
619 if (m->running_as != MANAGER_SESSION && m->system_bus)
620 m->api_bus = m->system_bus;
622 if (!(m->api_bus = dbus_bus_get_private(m->running_as == MANAGER_SESSION ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, &error))) {
623 log_debug("Failed to get API D-Bus connection, retrying later: %s", error.message);
624 dbus_error_free(&error);
628 dbus_connection_set_dispatch_status_function(m->api_bus, api_bus_dispatch_status, m, NULL);
629 m->request_api_bus_dispatch = true;
631 if ((r = bus_setup_loop(m, m->api_bus)) < 0) {
637 if (!dbus_connection_register_object_path(m->api_bus, "/org/freedesktop/systemd1", &bus_manager_vtable, m) ||
638 !dbus_connection_register_fallback(m->api_bus, "/org/freedesktop/systemd1/unit", &bus_unit_vtable, m) ||
639 !dbus_connection_register_fallback(m->api_bus, "/org/freedesktop/systemd1/job", &bus_job_vtable, m) ||
640 !dbus_connection_add_filter(m->api_bus, api_bus_message_filter, m, NULL)) {
645 dbus_bus_add_match(m->api_bus,
647 "sender='"DBUS_SERVICE_DBUS"',"
648 "interface='"DBUS_INTERFACE_DBUS"',"
649 "path='"DBUS_PATH_DBUS"'",
652 if (dbus_error_is_set(&error)) {
653 log_error("Failed to register match: %s", error.message);
654 dbus_error_free(&error);
659 if ((r = request_name(m)) < 0) {
664 log_debug("Successfully connected to API D-Bus bus %s as %s",
665 strnull((id = dbus_connection_get_server_id(m->api_bus))),
666 strnull(dbus_bus_get_unique_name(m->api_bus)));
670 if (!(m->subscribed = set_new(string_hash_func, string_compare_func)))
676 void bus_done_api(Manager *m) {
680 if (m->system_bus == m->api_bus)
681 m->system_bus = NULL;
683 dbus_connection_set_dispatch_status_function(m->api_bus, NULL, NULL, NULL);
684 dbus_connection_flush(m->api_bus);
685 dbus_connection_close(m->api_bus);
686 dbus_connection_unref(m->api_bus);
693 while ((c = set_steal_first(m->subscribed)))
696 set_free(m->subscribed);
697 m->subscribed = NULL;
700 if (m->name_data_slot >= 0)
701 dbus_pending_call_free_data_slot(&m->name_data_slot);
703 if (m->queued_message) {
704 dbus_message_unref(m->queued_message);
705 m->queued_message = NULL;
709 void bus_done_system(Manager *m) {
712 if (m->system_bus == m->api_bus)
716 dbus_connection_set_dispatch_status_function(m->system_bus, NULL, NULL, NULL);
717 dbus_connection_flush(m->system_bus);
718 dbus_connection_close(m->system_bus);
719 dbus_connection_unref(m->system_bus);
720 m->system_bus = NULL;
724 static void query_pid_pending_cb(DBusPendingCall *pending, void *userdata) {
725 Manager *m = userdata;
730 dbus_error_init(&error);
732 assert_se(name = dbus_pending_call_get_data(pending, m->name_data_slot));
733 assert_se(reply = dbus_pending_call_steal_reply(pending));
735 switch (dbus_message_get_type(reply)) {
737 case DBUS_MESSAGE_TYPE_ERROR:
739 assert_se(dbus_set_error_from_message(&error, reply));
740 log_warning("GetConnectionUnixProcessID() failed: %s", error.message);
743 case DBUS_MESSAGE_TYPE_METHOD_RETURN: {
746 if (!dbus_message_get_args(reply,
748 DBUS_TYPE_UINT32, &r,
749 DBUS_TYPE_INVALID)) {
750 log_error("Failed to parse GetConnectionUnixProcessID() reply: %s", error.message);
754 manager_dispatch_bus_query_pid_done(m, name, (pid_t) r);
759 assert_not_reached("Invalid reply message");
762 dbus_message_unref(reply);
763 dbus_error_free(&error);
766 int bus_query_pid(Manager *m, const char *name) {
767 DBusMessage *message = NULL;
768 DBusPendingCall *pending = NULL;
774 if (!(message = dbus_message_new_method_call(
778 "GetConnectionUnixProcessID")))
781 if (!(dbus_message_append_args(
783 DBUS_TYPE_STRING, &name,
787 if (!dbus_connection_send_with_reply(m->api_bus, message, &pending, -1))
790 if (!(n = strdup(name)))
793 if (!dbus_pending_call_set_data(pending, m->name_data_slot, n, free))
798 if (!dbus_pending_call_set_notify(pending, query_pid_pending_cb, m, NULL))
801 dbus_message_unref(message);
802 dbus_pending_call_unref(pending);
810 dbus_pending_call_cancel(pending);
811 dbus_pending_call_unref(pending);
815 dbus_message_unref(message);
820 DBusHandlerResult bus_default_message_handler(Manager *m, DBusMessage *message, const char*introspection, const BusProperty *properties) {
822 DBusMessage *reply = NULL;
828 dbus_error_init(&error);
830 if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect") && introspection) {
832 if (!(reply = dbus_message_new_method_return(message)))
835 if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &introspection, DBUS_TYPE_INVALID))
838 } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Properties", "Get") && properties) {
839 const char *interface, *property;
840 const BusProperty *p;
842 if (!dbus_message_get_args(
845 DBUS_TYPE_STRING, &interface,
846 DBUS_TYPE_STRING, &property,
848 return bus_send_error_reply(m, message, &error, -EINVAL);
850 for (p = properties; p->property; p++)
851 if (streq(p->interface, interface) && streq(p->property, property))
855 DBusMessageIter iter, sub;
857 if (!(reply = dbus_message_new_method_return(message)))
860 dbus_message_iter_init_append(reply, &iter);
862 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, p->signature, &sub))
865 if ((r = p->append(m, &sub, property, (void*) p->data)) < 0) {
870 dbus_message_unref(reply);
871 return bus_send_error_reply(m, message, NULL, r);
874 if (!dbus_message_iter_close_container(&iter, &sub))
877 } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Properties", "GetAll") && properties) {
878 const char *interface;
879 const BusProperty *p;
880 DBusMessageIter iter, sub, sub2, sub3;
883 if (!dbus_message_get_args(
886 DBUS_TYPE_STRING, &interface,
888 return bus_send_error_reply(m, message, &error, -EINVAL);
890 if (!(reply = dbus_message_new_method_return(message)))
893 dbus_message_iter_init_append(reply, &iter);
895 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &sub))
898 for (p = properties; p->property; p++) {
899 if (!streq(p->interface, interface))
902 if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_DICT_ENTRY, NULL, &sub2) ||
903 !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &p->property) ||
904 !dbus_message_iter_open_container(&sub2, DBUS_TYPE_VARIANT, p->signature, &sub3))
907 if ((r = p->append(m, &sub3, p->property, (void*) p->data)) < 0) {
912 dbus_message_unref(reply);
913 return bus_send_error_reply(m, message, NULL, r);
916 if (!dbus_message_iter_close_container(&sub2, &sub3) ||
917 !dbus_message_iter_close_container(&sub, &sub2))
923 if (!dbus_message_iter_close_container(&iter, &sub))
928 if (!dbus_connection_send(m->api_bus, reply, NULL))
931 dbus_message_unref(reply);
932 return DBUS_HANDLER_RESULT_HANDLED;
935 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
939 dbus_message_unref(reply);
941 dbus_error_free(&error);
943 return DBUS_HANDLER_RESULT_NEED_MEMORY;
946 static const char *error_to_dbus(int error) {
951 return DBUS_ERROR_INVALID_ARGS;
954 return DBUS_ERROR_NO_MEMORY;
958 return DBUS_ERROR_ACCESS_DENIED;
961 return DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN;
964 return DBUS_ERROR_FILE_NOT_FOUND;
967 return DBUS_ERROR_FILE_EXISTS;
970 return DBUS_ERROR_TIMEOUT;
973 return DBUS_ERROR_IO_ERROR;
978 return DBUS_ERROR_DISCONNECTED;
981 return DBUS_ERROR_FAILED;
984 DBusHandlerResult bus_send_error_reply(Manager *m, DBusMessage *message, DBusError *bus_error, int error) {
985 DBusMessage *reply = NULL;
986 const char *name, *text;
988 if (bus_error && dbus_error_is_set(bus_error)) {
989 name = bus_error->name;
990 text = bus_error->message;
992 name = error_to_dbus(error);
993 text = strerror(-error);
996 if (!(reply = dbus_message_new_error(message, name, text)))
999 if (!dbus_connection_send(m->api_bus, reply, NULL))
1002 dbus_message_unref(reply);
1005 dbus_error_free(bus_error);
1007 return DBUS_HANDLER_RESULT_HANDLED;
1011 dbus_message_unref(reply);
1014 dbus_error_free(bus_error);
1016 return DBUS_HANDLER_RESULT_NEED_MEMORY;
1019 int bus_property_append_string(Manager *m, DBusMessageIter *i, const char *property, void *data) {
1020 const char *t = data;
1029 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t))
1035 int bus_property_append_strv(Manager *m, DBusMessageIter *i, const char *property, void *data) {
1036 DBusMessageIter sub;
1043 if (!dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, "s", &sub))
1047 if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, t))
1050 if (!dbus_message_iter_close_container(i, &sub))
1056 int bus_property_append_bool(Manager *m, DBusMessageIter *i, const char *property, void *data) {
1067 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &db))
1073 int bus_property_append_uint64(Manager *m, DBusMessageIter *i, const char *property, void *data) {
1079 /* Let's ensure that pid_t is actually 64bit, and hence this
1080 * function can be used for usec_t */
1081 assert_cc(sizeof(uint64_t) == sizeof(usec_t));
1083 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, data))
1089 int bus_property_append_uint32(Manager *m, DBusMessageIter *i, const char *property, void *data) {
1095 /* Let's ensure that pid_t and mode_t is actually 32bit, and
1096 * hence this function can be used for pid_t/mode_t */
1097 assert_cc(sizeof(uint32_t) == sizeof(pid_t));
1098 assert_cc(sizeof(uint32_t) == sizeof(mode_t));
1099 assert_cc(sizeof(uint32_t) == sizeof(unsigned));
1101 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT32, data))
1107 int bus_property_append_int32(Manager *m, DBusMessageIter *i, const char *property, void *data) {
1113 assert_cc(sizeof(int32_t) == sizeof(int));
1115 if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, data))
1121 int bus_parse_strv(DBusMessage *m, char ***_l) {
1122 DBusMessageIter iter, sub;
1123 unsigned n = 0, i = 0;
1129 if (!dbus_message_iter_init(m, &iter) ||
1130 dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
1131 dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_STRING)
1134 dbus_message_iter_recurse(&iter, &sub);
1136 while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
1138 dbus_message_iter_next(&sub);
1141 if (!(l = new(char*, n+1)))
1144 assert_se(dbus_message_iter_init(m, &iter));
1145 dbus_message_iter_recurse(&iter, &sub);
1147 while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
1150 assert_se(dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_STRING);
1151 dbus_message_iter_get_basic(&sub, &s);
1153 if (!(l[i++] = strdup(s))) {
1158 dbus_message_iter_next(&sub);