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"
36 static void api_bus_dispatch_status(DBusConnection
*bus
, DBusDispatchStatus status
, void *data
) {
45 assert(m
->api_bus
== bus
);
47 m
->request_api_bus_dispatch
= status
!= DBUS_DISPATCH_COMPLETE
;
50 static void system_bus_dispatch_status(DBusConnection
*bus
, DBusDispatchStatus status
, void *data
) {
59 assert(m
->system_bus
== bus
);
61 m
->request_system_bus_dispatch
= status
!= DBUS_DISPATCH_COMPLETE
;
64 static uint32_t bus_flags_to_events(DBusWatch
*bus_watch
) {
70 /* no watch flags for disabled watches */
71 if (!dbus_watch_get_enabled(bus_watch
))
74 flags
= dbus_watch_get_flags(bus_watch
);
76 if (flags
& DBUS_WATCH_READABLE
)
78 if (flags
& DBUS_WATCH_WRITABLE
)
81 return events
| EPOLLHUP
| EPOLLERR
;
84 static unsigned events_to_bus_flags(uint32_t events
) {
88 flags
|= DBUS_WATCH_READABLE
;
89 if (events
& EPOLLOUT
)
90 flags
|= DBUS_WATCH_WRITABLE
;
91 if (events
& EPOLLHUP
)
92 flags
|= DBUS_WATCH_HANGUP
;
93 if (events
& EPOLLERR
)
94 flags
|= DBUS_WATCH_ERROR
;
99 void bus_watch_event(Manager
*m
, Watch
*w
, int events
) {
103 /* This is called by the event loop whenever there is
104 * something happening on D-Bus' file handles. */
106 if (!dbus_watch_get_enabled(w
->data
.bus_watch
))
109 dbus_watch_handle(w
->data
.bus_watch
, events_to_bus_flags(events
));
112 static dbus_bool_t
bus_add_watch(DBusWatch
*bus_watch
, void *data
) {
115 struct epoll_event ev
;
120 if (!(w
= new0(Watch
, 1)))
123 w
->fd
= dbus_watch_get_unix_fd(bus_watch
);
124 w
->type
= WATCH_DBUS_WATCH
;
125 w
->data
.bus_watch
= bus_watch
;
128 ev
.events
= bus_flags_to_events(bus_watch
);
131 if (epoll_ctl(m
->epoll_fd
, EPOLL_CTL_ADD
, w
->fd
, &ev
) < 0) {
133 if (errno
!= EEXIST
) {
138 /* Hmm, bloody D-Bus creates multiple watches on the
139 * same fd. epoll() does not like that. As a dirty
140 * hack we simply dup() the fd and hence get a second
141 * one we can safely add to the epoll(). */
143 if ((w
->fd
= dup(w
->fd
)) < 0) {
148 if (epoll_ctl(m
->epoll_fd
, EPOLL_CTL_ADD
, w
->fd
, &ev
) < 0) {
150 close_nointr_nofail(w
->fd
);
154 w
->fd_is_dupped
= true;
157 dbus_watch_set_data(bus_watch
, w
, NULL
);
162 static void bus_remove_watch(DBusWatch
*bus_watch
, void *data
) {
169 if (!(w
= dbus_watch_get_data(bus_watch
)))
172 assert(w
->type
== WATCH_DBUS_WATCH
);
173 assert_se(epoll_ctl(m
->epoll_fd
, EPOLL_CTL_DEL
, w
->fd
, NULL
) >= 0);
176 close_nointr_nofail(w
->fd
);
181 static void bus_toggle_watch(DBusWatch
*bus_watch
, void *data
) {
184 struct epoll_event ev
;
189 assert_se(w
= dbus_watch_get_data(bus_watch
));
190 assert(w
->type
== WATCH_DBUS_WATCH
);
193 ev
.events
= bus_flags_to_events(bus_watch
);
196 assert_se(epoll_ctl(m
->epoll_fd
, EPOLL_CTL_MOD
, w
->fd
, &ev
) == 0);
199 static int bus_timeout_arm(Manager
*m
, Watch
*w
) {
200 struct itimerspec its
;
207 if (dbus_timeout_get_enabled(w
->data
.bus_timeout
)) {
208 timespec_store(&its
.it_value
, dbus_timeout_get_interval(w
->data
.bus_timeout
) * USEC_PER_MSEC
);
209 its
.it_interval
= its
.it_interval
;
212 if (timerfd_settime(w
->fd
, 0, &its
, NULL
) < 0)
218 void bus_timeout_event(Manager
*m
, Watch
*w
, int events
) {
222 /* This is called by the event loop whenever there is
223 * something happening on D-Bus' file handles. */
225 if (!(dbus_timeout_get_enabled(w
->data
.bus_timeout
)))
228 dbus_timeout_handle(w
->data
.bus_timeout
);
231 static dbus_bool_t
bus_add_timeout(DBusTimeout
*timeout
, void *data
) {
234 struct epoll_event ev
;
239 if (!(w
= new0(Watch
, 1)))
242 if (!(w
->fd
= timerfd_create(CLOCK_MONOTONIC
, TFD_NONBLOCK
|TFD_CLOEXEC
)) < 0)
245 w
->type
= WATCH_DBUS_TIMEOUT
;
246 w
->data
.bus_timeout
= timeout
;
248 if (bus_timeout_arm(m
, w
) < 0)
255 if (epoll_ctl(m
->epoll_fd
, EPOLL_CTL_ADD
, w
->fd
, &ev
) < 0)
258 dbus_timeout_set_data(timeout
, w
, NULL
);
264 close_nointr_nofail(w
->fd
);
270 static void bus_remove_timeout(DBusTimeout
*timeout
, void *data
) {
277 if (!(w
= dbus_timeout_get_data(timeout
)))
280 assert(w
->type
== WATCH_DBUS_TIMEOUT
);
281 assert_se(epoll_ctl(m
->epoll_fd
, EPOLL_CTL_DEL
, w
->fd
, NULL
) >= 0);
282 close_nointr_nofail(w
->fd
);
286 static void bus_toggle_timeout(DBusTimeout
*timeout
, void *data
) {
294 assert_se(w
= dbus_timeout_get_data(timeout
));
295 assert(w
->type
== WATCH_DBUS_TIMEOUT
);
297 if ((r
= bus_timeout_arm(m
, w
)) < 0)
298 log_error("Failed to rearm timer: %s", strerror(-r
));
301 static DBusHandlerResult
api_bus_message_filter(DBusConnection
*connection
, DBusMessage
*message
, void *data
) {
309 dbus_error_init(&error
);
311 /* log_debug("Got D-Bus request: %s.%s() on %s", */
312 /* dbus_message_get_interface(message), */
313 /* dbus_message_get_member(message), */
314 /* dbus_message_get_path(message)); */
316 if (dbus_message_is_signal(message
, DBUS_INTERFACE_LOCAL
, "Disconnected")) {
317 log_error("Warning! API D-Bus connection terminated.");
320 } else if (dbus_message_is_signal(message
, DBUS_INTERFACE_DBUS
, "NameOwnerChanged")) {
321 const char *name
, *old_owner
, *new_owner
;
323 if (!dbus_message_get_args(message
, &error
,
324 DBUS_TYPE_STRING
, &name
,
325 DBUS_TYPE_STRING
, &old_owner
,
326 DBUS_TYPE_STRING
, &new_owner
,
328 log_error("Failed to parse NameOwnerChanged message: %s", error
.message
);
330 if (set_remove(m
->subscribed
, (char*) name
))
331 log_debug("Subscription client vanished: %s (left: %u)", name
, set_size(m
->subscribed
));
333 if (old_owner
[0] == 0)
336 if (new_owner
[0] == 0)
339 manager_dispatch_bus_name_owner_changed(m
, name
, old_owner
, new_owner
);
343 dbus_error_free(&error
);
344 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
347 static DBusHandlerResult
system_bus_message_filter(DBusConnection
*connection
, DBusMessage
*message
, void *data
) {
355 dbus_error_init(&error
);
357 /* log_debug("Got D-Bus request: %s.%s() on %s", */
358 /* dbus_message_get_interface(message), */
359 /* dbus_message_get_member(message), */
360 /* dbus_message_get_path(message)); */
362 if (dbus_message_is_signal(message
, DBUS_INTERFACE_LOCAL
, "Disconnected")) {
363 log_error("Warning! System D-Bus connection terminated.");
366 } if (dbus_message_is_signal(message
, "org.freedesktop.systemd1.Agent", "Released")) {
369 if (!dbus_message_get_args(message
, &error
,
370 DBUS_TYPE_STRING
, &cgroup
,
372 log_error("Failed to parse Released message: %s", error
.message
);
374 cgroup_notify_empty(m
, cgroup
);
377 dbus_error_free(&error
);
378 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
381 unsigned bus_dispatch(Manager
*m
) {
384 if (m
->queued_message
) {
385 /* If we cannot get rid of this message we won't
386 * dispatch any D-Bus messages, so that we won't end
387 * up wanting to queue another message. */
389 if (!dbus_connection_send(m
->api_bus
, m
->queued_message
, NULL
))
392 dbus_message_unref(m
->queued_message
);
393 m
->queued_message
= NULL
;
396 if (m
->request_api_bus_dispatch
) {
397 if (dbus_connection_dispatch(m
->api_bus
) == DBUS_DISPATCH_COMPLETE
)
398 m
->request_api_bus_dispatch
= false;
403 if (m
->request_system_bus_dispatch
) {
404 if (dbus_connection_dispatch(m
->system_bus
) == DBUS_DISPATCH_COMPLETE
)
405 m
->request_system_bus_dispatch
= false;
413 static void request_name_pending_cb(DBusPendingCall
*pending
, void *userdata
) {
417 dbus_error_init(&error
);
419 assert_se(reply
= dbus_pending_call_steal_reply(pending
));
421 switch (dbus_message_get_type(reply
)) {
423 case DBUS_MESSAGE_TYPE_ERROR
:
425 assert_se(dbus_set_error_from_message(&error
, reply
));
426 log_warning("RequestName() failed: %s", error
.message
);
429 case DBUS_MESSAGE_TYPE_METHOD_RETURN
: {
432 if (!dbus_message_get_args(reply
,
434 DBUS_TYPE_UINT32
, &r
,
435 DBUS_TYPE_INVALID
)) {
436 log_error("Failed to parse RequestName() reply: %s", error
.message
);
441 log_debug("Successfully acquired name.");
443 log_error("Name already owned.");
449 assert_not_reached("Invalid reply message");
452 dbus_message_unref(reply
);
453 dbus_error_free(&error
);
456 static int request_name(Manager
*m
) {
457 const char *name
= "org.freedesktop.systemd1";
459 DBusMessage
*message
= NULL
;
460 DBusPendingCall
*pending
= NULL
;
462 if (!(message
= dbus_message_new_method_call(
469 if (!dbus_message_append_args(
471 DBUS_TYPE_STRING
, &name
,
472 DBUS_TYPE_UINT32
, &flags
,
476 if (!dbus_connection_send_with_reply(m
->api_bus
, message
, &pending
, -1))
479 if (!dbus_pending_call_set_notify(pending
, request_name_pending_cb
, m
, NULL
))
482 dbus_message_unref(message
);
483 dbus_pending_call_unref(pending
);
485 /* We simple ask for the name and don't wait for it. Sooner or
486 * later we'll have it. */
492 dbus_pending_call_cancel(pending
);
493 dbus_pending_call_unref(pending
);
497 dbus_message_unref(message
);
502 static int bus_setup_loop(Manager
*m
, DBusConnection
*bus
) {
506 dbus_connection_set_exit_on_disconnect(bus
, FALSE
);
508 if (!dbus_connection_set_watch_functions(bus
, bus_add_watch
, bus_remove_watch
, bus_toggle_watch
, m
, NULL
) ||
509 !dbus_connection_set_timeout_functions(bus
, bus_add_timeout
, bus_remove_timeout
, bus_toggle_timeout
, m
, NULL
))
515 int bus_init_system(Manager
*m
) {
522 dbus_error_init(&error
);
527 if (m
->running_as
!= MANAGER_SESSION
&& m
->api_bus
)
528 m
->system_bus
= m
->api_bus
;
530 if (!(m
->system_bus
= dbus_bus_get_private(DBUS_BUS_SYSTEM
, &error
))) {
531 log_debug("Failed to get system D-Bus connection, retrying later: %s", error
.message
);
532 dbus_error_free(&error
);
536 dbus_connection_set_dispatch_status_function(m
->system_bus
, system_bus_dispatch_status
, m
, NULL
);
537 m
->request_system_bus_dispatch
= true;
539 if ((r
= bus_setup_loop(m
, m
->system_bus
)) < 0) {
545 if (!dbus_connection_add_filter(m
->system_bus
, system_bus_message_filter
, m
, NULL
)) {
550 dbus_bus_add_match(m
->system_bus
,
552 "interface='org.freedesktop.systemd1.Agent',"
553 "path='/org/freedesktop/systemd1/agent'",
556 if (dbus_error_is_set(&error
)) {
557 log_error("Failed to register match: %s", error
.message
);
558 dbus_error_free(&error
);
563 log_debug("Successfully connected to system D-Bus bus %s as %s",
564 strnull((id
= dbus_connection_get_server_id(m
->system_bus
))),
565 strnull(dbus_bus_get_unique_name(m
->system_bus
)));
571 int bus_init_api(Manager
*m
) {
578 dbus_error_init(&error
);
583 if (m
->name_data_slot
< 0)
584 if (!dbus_pending_call_allocate_data_slot(&m
->name_data_slot
))
587 if (m
->running_as
!= MANAGER_SESSION
&& m
->system_bus
)
588 m
->api_bus
= m
->system_bus
;
590 if (!(m
->api_bus
= dbus_bus_get_private(m
->running_as
== MANAGER_SESSION
? DBUS_BUS_SESSION
: DBUS_BUS_SYSTEM
, &error
))) {
591 log_debug("Failed to get API D-Bus connection, retrying later: %s", error
.message
);
592 dbus_error_free(&error
);
596 dbus_connection_set_dispatch_status_function(m
->api_bus
, api_bus_dispatch_status
, m
, NULL
);
597 m
->request_api_bus_dispatch
= true;
599 if ((r
= bus_setup_loop(m
, m
->api_bus
)) < 0) {
605 if (!dbus_connection_register_object_path(m
->api_bus
, "/org/freedesktop/systemd1", &bus_manager_vtable
, m
) ||
606 !dbus_connection_register_fallback(m
->api_bus
, "/org/freedesktop/systemd1/unit", &bus_unit_vtable
, m
) ||
607 !dbus_connection_register_fallback(m
->api_bus
, "/org/freedesktop/systemd1/job", &bus_job_vtable
, m
) ||
608 !dbus_connection_add_filter(m
->api_bus
, api_bus_message_filter
, m
, NULL
)) {
613 dbus_bus_add_match(m
->api_bus
,
615 "sender='"DBUS_SERVICE_DBUS
"',"
616 "interface='"DBUS_INTERFACE_DBUS
"',"
617 "path='"DBUS_PATH_DBUS
"'",
620 if (dbus_error_is_set(&error
)) {
621 log_error("Failed to register match: %s", error
.message
);
622 dbus_error_free(&error
);
627 if ((r
= request_name(m
)) < 0) {
632 log_debug("Successfully connected to API D-Bus bus %s as %s",
633 strnull((id
= dbus_connection_get_server_id(m
->api_bus
))),
634 strnull(dbus_bus_get_unique_name(m
->api_bus
)));
638 if (!(m
->subscribed
= set_new(string_hash_func
, string_compare_func
)))
644 void bus_done_api(Manager
*m
) {
648 if (m
->system_bus
== m
->api_bus
)
649 m
->system_bus
= NULL
;
651 dbus_connection_set_dispatch_status_function(m
->api_bus
, NULL
, NULL
, NULL
);
652 dbus_connection_flush(m
->api_bus
);
653 dbus_connection_close(m
->api_bus
);
654 dbus_connection_unref(m
->api_bus
);
661 while ((c
= set_steal_first(m
->subscribed
)))
664 set_free(m
->subscribed
);
665 m
->subscribed
= NULL
;
668 if (m
->name_data_slot
>= 0)
669 dbus_pending_call_free_data_slot(&m
->name_data_slot
);
671 if (m
->queued_message
) {
672 dbus_message_unref(m
->queued_message
);
673 m
->queued_message
= NULL
;
677 void bus_done_system(Manager
*m
) {
680 if (m
->system_bus
== m
->api_bus
)
684 dbus_connection_set_dispatch_status_function(m
->system_bus
, NULL
, NULL
, NULL
);
685 dbus_connection_flush(m
->system_bus
);
686 dbus_connection_close(m
->system_bus
);
687 dbus_connection_unref(m
->system_bus
);
688 m
->system_bus
= NULL
;
692 static void query_pid_pending_cb(DBusPendingCall
*pending
, void *userdata
) {
693 Manager
*m
= userdata
;
698 dbus_error_init(&error
);
700 assert_se(name
= dbus_pending_call_get_data(pending
, m
->name_data_slot
));
701 assert_se(reply
= dbus_pending_call_steal_reply(pending
));
703 switch (dbus_message_get_type(reply
)) {
705 case DBUS_MESSAGE_TYPE_ERROR
:
707 assert_se(dbus_set_error_from_message(&error
, reply
));
708 log_warning("GetConnectionUnixProcessID() failed: %s", error
.message
);
711 case DBUS_MESSAGE_TYPE_METHOD_RETURN
: {
714 if (!dbus_message_get_args(reply
,
716 DBUS_TYPE_UINT32
, &r
,
717 DBUS_TYPE_INVALID
)) {
718 log_error("Failed to parse GetConnectionUnixProcessID() reply: %s", error
.message
);
722 manager_dispatch_bus_query_pid_done(m
, name
, (pid_t
) r
);
727 assert_not_reached("Invalid reply message");
730 dbus_message_unref(reply
);
731 dbus_error_free(&error
);
734 int bus_query_pid(Manager
*m
, const char *name
) {
735 DBusMessage
*message
= NULL
;
736 DBusPendingCall
*pending
= NULL
;
742 if (!(message
= dbus_message_new_method_call(
746 "GetConnectionUnixProcessID")))
749 if (!(dbus_message_append_args(
751 DBUS_TYPE_STRING
, &name
,
755 if (!dbus_connection_send_with_reply(m
->api_bus
, message
, &pending
, -1))
758 if (!(n
= strdup(name
)))
761 if (!dbus_pending_call_set_data(pending
, m
->name_data_slot
, n
, free
))
766 if (!dbus_pending_call_set_notify(pending
, query_pid_pending_cb
, m
, NULL
))
769 dbus_message_unref(message
);
770 dbus_pending_call_unref(pending
);
778 dbus_pending_call_cancel(pending
);
779 dbus_pending_call_unref(pending
);
783 dbus_message_unref(message
);
788 DBusHandlerResult
bus_default_message_handler(Manager
*m
, DBusMessage
*message
, const char*introspection
, const BusProperty
*properties
) {
790 DBusMessage
*reply
= NULL
;
796 dbus_error_init(&error
);
798 if (dbus_message_is_method_call(message
, "org.freedesktop.DBus.Introspectable", "Introspect") && introspection
) {
800 if (!(reply
= dbus_message_new_method_return(message
)))
803 if (!dbus_message_append_args(reply
, DBUS_TYPE_STRING
, &introspection
, DBUS_TYPE_INVALID
))
806 } else if (dbus_message_is_method_call(message
, "org.freedesktop.DBus.Properties", "Get") && properties
) {
807 const char *interface
, *property
;
808 const BusProperty
*p
;
810 if (!dbus_message_get_args(
813 DBUS_TYPE_STRING
, &interface
,
814 DBUS_TYPE_STRING
, &property
,
816 return bus_send_error_reply(m
, message
, &error
, -EINVAL
);
818 for (p
= properties
; p
->property
; p
++)
819 if (streq(p
->interface
, interface
) && streq(p
->property
, property
))
823 DBusMessageIter iter
, sub
;
825 if (!(reply
= dbus_message_new_method_return(message
)))
828 dbus_message_iter_init_append(reply
, &iter
);
830 if (!dbus_message_iter_open_container(&iter
, DBUS_TYPE_VARIANT
, p
->signature
, &sub
))
833 if ((r
= p
->append(m
, &sub
, property
, (void*) p
->data
)) < 0) {
838 dbus_message_unref(reply
);
839 return bus_send_error_reply(m
, message
, NULL
, r
);
842 if (!dbus_message_iter_close_container(&iter
, &sub
))
845 } else if (dbus_message_is_method_call(message
, "org.freedesktop.DBus.Properties", "GetAll") && properties
) {
846 const char *interface
;
847 const BusProperty
*p
;
848 DBusMessageIter iter
, sub
, sub2
, sub3
;
851 if (!dbus_message_get_args(
854 DBUS_TYPE_STRING
, &interface
,
856 return bus_send_error_reply(m
, message
, &error
, -EINVAL
);
858 if (!(reply
= dbus_message_new_method_return(message
)))
861 dbus_message_iter_init_append(reply
, &iter
);
863 if (!dbus_message_iter_open_container(&iter
, DBUS_TYPE_ARRAY
, "{sv}", &sub
))
866 for (p
= properties
; p
->property
; p
++) {
867 if (!streq(p
->interface
, interface
))
870 if (!dbus_message_iter_open_container(&sub
, DBUS_TYPE_DICT_ENTRY
, NULL
, &sub2
) ||
871 !dbus_message_iter_append_basic(&sub2
, DBUS_TYPE_STRING
, &p
->property
) ||
872 !dbus_message_iter_open_container(&sub2
, DBUS_TYPE_VARIANT
, p
->signature
, &sub3
))
875 if ((r
= p
->append(m
, &sub3
, p
->property
, (void*) p
->data
)) < 0) {
880 dbus_message_unref(reply
);
881 return bus_send_error_reply(m
, message
, NULL
, r
);
884 if (!dbus_message_iter_close_container(&sub2
, &sub3
) ||
885 !dbus_message_iter_close_container(&sub
, &sub2
))
891 if (!dbus_message_iter_close_container(&iter
, &sub
))
896 if (!dbus_connection_send(m
->api_bus
, reply
, NULL
))
899 dbus_message_unref(reply
);
900 return DBUS_HANDLER_RESULT_HANDLED
;
903 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
907 dbus_message_unref(reply
);
909 dbus_error_free(&error
);
911 return DBUS_HANDLER_RESULT_NEED_MEMORY
;
914 static const char *error_to_dbus(int error
) {
919 return DBUS_ERROR_INVALID_ARGS
;
922 return DBUS_ERROR_NO_MEMORY
;
926 return DBUS_ERROR_ACCESS_DENIED
;
929 return DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN
;
932 return DBUS_ERROR_FILE_NOT_FOUND
;
935 return DBUS_ERROR_FILE_EXISTS
;
938 return DBUS_ERROR_TIMEOUT
;
941 return DBUS_ERROR_IO_ERROR
;
946 return DBUS_ERROR_DISCONNECTED
;
949 return DBUS_ERROR_FAILED
;
952 DBusHandlerResult
bus_send_error_reply(Manager
*m
, DBusMessage
*message
, DBusError
*bus_error
, int error
) {
953 DBusMessage
*reply
= NULL
;
954 const char *name
, *text
;
956 if (bus_error
&& dbus_error_is_set(bus_error
)) {
957 name
= bus_error
->name
;
958 text
= bus_error
->message
;
960 name
= error_to_dbus(error
);
961 text
= strerror(-error
);
964 if (!(reply
= dbus_message_new_error(message
, name
, text
)))
967 if (!dbus_connection_send(m
->api_bus
, reply
, NULL
))
970 dbus_message_unref(reply
);
973 dbus_error_free(bus_error
);
975 return DBUS_HANDLER_RESULT_HANDLED
;
979 dbus_message_unref(reply
);
982 dbus_error_free(bus_error
);
984 return DBUS_HANDLER_RESULT_NEED_MEMORY
;
987 int bus_property_append_string(Manager
*m
, DBusMessageIter
*i
, const char *property
, void *data
) {
988 const char *t
= data
;
997 if (!dbus_message_iter_append_basic(i
, DBUS_TYPE_STRING
, &t
))
1003 int bus_property_append_strv(Manager
*m
, DBusMessageIter
*i
, const char *property
, void *data
) {
1004 DBusMessageIter sub
;
1011 if (!dbus_message_iter_open_container(i
, DBUS_TYPE_ARRAY
, "s", &sub
))
1015 if (!dbus_message_iter_append_basic(&sub
, DBUS_TYPE_STRING
, t
))
1018 if (!dbus_message_iter_close_container(i
, &sub
))
1024 int bus_property_append_bool(Manager
*m
, DBusMessageIter
*i
, const char *property
, void *data
) {
1035 if (!dbus_message_iter_append_basic(i
, DBUS_TYPE_BOOLEAN
, &db
))
1041 int bus_property_append_uint64(Manager
*m
, DBusMessageIter
*i
, const char *property
, void *data
) {
1047 /* Let's ensure that pid_t is actually 64bit, and hence this
1048 * function can be used for usec_t */
1049 assert_cc(sizeof(uint64_t) == sizeof(usec_t
));
1051 if (!dbus_message_iter_append_basic(i
, DBUS_TYPE_UINT64
, data
))
1057 int bus_property_append_uint32(Manager
*m
, DBusMessageIter
*i
, const char *property
, void *data
) {
1063 /* Let's ensure that pid_t and mode_t is actually 32bit, and
1064 * hence this function can be used for pid_t/mode_t */
1065 assert_cc(sizeof(uint32_t) == sizeof(pid_t
));
1066 assert_cc(sizeof(uint32_t) == sizeof(mode_t
));
1067 assert_cc(sizeof(uint32_t) == sizeof(unsigned));
1069 if (!dbus_message_iter_append_basic(i
, DBUS_TYPE_UINT32
, data
))
1075 int bus_property_append_int32(Manager
*m
, DBusMessageIter
*i
, const char *property
, void *data
) {
1081 assert_cc(sizeof(int32_t) == sizeof(int));
1083 if (!dbus_message_iter_append_basic(i
, DBUS_TYPE_INT32
, data
))