1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2008, 2009 Nedko Arnaudov <nedko@arnaudov.name>
6 * Copyright (C) 2008 Juuso Alasuutari <juuso.alasuutari@gmail.com>
8 **************************************************************************
9 * This file contains code of the D-Bus helpers
10 **************************************************************************
12 * Licensed under the Academic Free License version 2.1
14 * LADI Session Handler is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * LADI Session Handler is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
26 * or write to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
31 #include <dbus/dbus.h>
38 #include "../assert.h"
39 #include "../common/klist.h"
41 DBusConnection
* g_dbus_connection
;
42 DBusError g_dbus_error
;
44 struct dbus_signal_hook_descriptor
46 struct list_head siblings
;
50 const struct dbus_signal_hook
* signal_hooks
;
53 struct dbus_service_descriptor
55 struct list_head siblings
;
57 void (* lifetime_hook_function
)(bool appeared
);
58 struct list_head hooks
;
61 LIST_HEAD(g_dbus_services
);
63 bool dbus_iter_get_dict_entry(DBusMessageIter
* iter
, const char ** key_ptr
, void * value_ptr
, int * type_ptr
, int * size_ptr
)
65 if (!iter
|| !key_ptr
|| !value_ptr
|| !type_ptr
) {
66 log_error("Invalid arguments");
70 DBusMessageIter dict_iter
, variant_iter
;
72 if (dbus_message_iter_get_arg_type(iter
) != DBUS_TYPE_DICT_ENTRY
) {
73 log_error("Iterator does not point to a dict entry container");
77 dbus_message_iter_recurse(iter
, &dict_iter
);
79 if (dbus_message_iter_get_arg_type(&dict_iter
) != DBUS_TYPE_STRING
) {
80 log_error("Cannot find key in dict entry container");
84 dbus_message_iter_get_basic(&dict_iter
, key_ptr
);
86 if (!dbus_message_iter_next(&dict_iter
)
87 || dbus_message_iter_get_arg_type(&dict_iter
) != DBUS_TYPE_VARIANT
) {
88 log_error("Cannot find variant container in dict entry");
92 dbus_message_iter_recurse(&dict_iter
, &variant_iter
);
94 *type_ptr
= dbus_message_iter_get_arg_type(&variant_iter
);
95 if (*type_ptr
== DBUS_TYPE_INVALID
) {
96 log_error("Cannot find value in variant container");
100 if (*type_ptr
== DBUS_TYPE_ARRAY
) {
101 DBusMessageIter array_iter
;
104 if (dbus_message_iter_get_element_type(&variant_iter
)
106 log_error("Dict entry value is a non-byte array");
111 dbus_message_iter_recurse(&variant_iter
, &array_iter
);
112 dbus_message_iter_get_fixed_array(&array_iter
, value_ptr
, &n
);
117 dbus_message_iter_get_basic(&variant_iter
, value_ptr
);
123 * Append a variant type to a D-Bus message.
124 * Return false if something fails, true otherwise.
126 bool dbus_iter_append_variant(DBusMessageIter
* iter
, int type
, const void * arg
)
128 DBusMessageIter sub_iter
;
134 /* Open a variant container. */
135 if (!dbus_message_iter_open_container(iter
, DBUS_TYPE_VARIANT
, (const char *)s
, &sub_iter
))
138 /* Append the supplied value. */
139 if (!dbus_message_iter_append_basic(&sub_iter
, type
, arg
))
141 dbus_message_iter_close_container(iter
, &sub_iter
);
145 /* Close the container. */
146 if (!dbus_message_iter_close_container(iter
, &sub_iter
))
152 static __inline__
bool dbus_iter_append_variant_raw(DBusMessageIter
* iter
, const void * buf
, int len
)
154 DBusMessageIter variant_iter
, array_iter
;
156 /* Open a variant container. */
157 if (!dbus_message_iter_open_container(iter
, DBUS_TYPE_VARIANT
,
158 "ay", &variant_iter
))
161 /* Open an array container. */
162 if (!dbus_message_iter_open_container(&variant_iter
, DBUS_TYPE_ARRAY
,
166 /* Append the supplied data. */
167 if (!dbus_message_iter_append_fixed_array(&array_iter
, DBUS_TYPE_BYTE
, buf
, len
)) {
168 dbus_message_iter_close_container(&variant_iter
, &array_iter
);
172 /* Close the containers. */
173 if (!dbus_message_iter_close_container(&variant_iter
, &array_iter
))
175 else if (!dbus_message_iter_close_container(iter
, &variant_iter
))
181 dbus_message_iter_close_container(iter
, &variant_iter
);
185 bool dbus_iter_append_dict_entry(DBusMessageIter
* iter
, int type
, const char * key
, const void * value
, int length
)
187 DBusMessageIter dict_iter
;
189 if (!dbus_message_iter_open_container(iter
, DBUS_TYPE_DICT_ENTRY
, NULL
, &dict_iter
))
192 if (!dbus_message_iter_append_basic(&dict_iter
, DBUS_TYPE_STRING
, &key
))
197 if (!dbus_iter_append_variant_raw(&dict_iter
, value
, length
))
200 else if (!dbus_iter_append_variant(&dict_iter
, type
, value
))
205 if (!dbus_message_iter_close_container(iter
, &dict_iter
))
211 dbus_message_iter_close_container(iter
, &dict_iter
);
215 bool dbus_maybe_add_dict_entry_string(DBusMessageIter
*dict_iter_ptr
, const char * key
, const char * value
)
217 DBusMessageIter dict_entry_iter
;
224 if (!dbus_message_iter_open_container(dict_iter_ptr
, DBUS_TYPE_DICT_ENTRY
, NULL
, &dict_entry_iter
))
229 if (!dbus_message_iter_append_basic(&dict_entry_iter
, DBUS_TYPE_STRING
, (const void *) &key
))
231 dbus_message_iter_close_container(dict_iter_ptr
, &dict_entry_iter
);
235 dbus_iter_append_variant(&dict_entry_iter
, DBUS_TYPE_STRING
, &value
);
237 if (!dbus_message_iter_close_container(dict_iter_ptr
, &dict_entry_iter
))
245 bool dbus_add_dict_entry_uint32(DBusMessageIter
* dict_iter_ptr
, const char * key
, dbus_uint32_t value
)
247 DBusMessageIter dict_entry_iter
;
249 if (!dbus_message_iter_open_container(dict_iter_ptr
, DBUS_TYPE_DICT_ENTRY
, NULL
, &dict_entry_iter
))
254 if (!dbus_message_iter_append_basic(&dict_entry_iter
, DBUS_TYPE_STRING
, (const void *) &key
))
256 dbus_message_iter_close_container(dict_iter_ptr
, &dict_entry_iter
);
260 dbus_iter_append_variant(&dict_entry_iter
, DBUS_TYPE_UINT32
, &value
);
262 if (!dbus_message_iter_close_container(dict_iter_ptr
, &dict_entry_iter
))
270 bool dbus_add_dict_entry_bool(DBusMessageIter
* dict_iter_ptr
, const char * key
, dbus_bool_t value
)
272 DBusMessageIter dict_entry_iter
;
274 if (!dbus_message_iter_open_container(dict_iter_ptr
, DBUS_TYPE_DICT_ENTRY
, NULL
, &dict_entry_iter
))
279 if (!dbus_message_iter_append_basic(&dict_entry_iter
, DBUS_TYPE_STRING
, (const void *) &key
))
281 dbus_message_iter_close_container(dict_iter_ptr
, &dict_entry_iter
);
285 dbus_iter_append_variant(&dict_entry_iter
, DBUS_TYPE_BOOLEAN
, &value
);
287 if (!dbus_message_iter_close_container(dict_iter_ptr
, &dict_entry_iter
))
297 const char * service
,
301 const char * input_signature
,
304 DBusMessageIter iter
;
305 DBusMessage
* request_ptr
;
306 DBusMessage
* reply_ptr
;
307 const char * output_signature
;
308 const char * reply_signature
;
311 void * parameter_ptr
;
313 DBusSignatureIter sig_iter
;
315 //log_info("dbus_call('%s', '%s', '%s', '%s')", service, object, iface, method);
318 va_start(ap
, input_signature
);
320 if (input_signature
!= NULL
)
322 if (!dbus_signature_validate(input_signature
, NULL
))
324 log_error("input signature '%s' is invalid", input_signature
);
328 dbus_signature_iter_init(&sig_iter
, input_signature
);
330 request_ptr
= dbus_message_new_method_call(service
, object
, iface
, method
);
331 if (request_ptr
== NULL
)
333 log_error("dbus_message_new_method_call() failed.");
337 dbus_message_iter_init_append(request_ptr
, &iter
);
339 while (*input_signature
!= '\0')
341 type
= dbus_signature_iter_get_current_type(&sig_iter
);
342 if (!dbus_type_is_basic(type
))
344 log_error("non-basic input parameter '%c' (%d)", *input_signature
, type
);
348 parameter_ptr
= va_arg(ap
, void *);
350 if (!dbus_message_iter_append_basic(&iter
, type
, parameter_ptr
))
352 log_error("dbus_message_iter_append_basic() failed.");
356 dbus_signature_iter_next(&sig_iter
);
362 request_ptr
= va_arg(ap
, DBusMessage
*);
365 output_signature
= va_arg(ap
, const char *);
367 reply_ptr
= dbus_connection_send_with_reply_and_block(
370 DBUS_CALL_DEFAULT_TIMEOUT
,
373 if (input_signature
!= NULL
)
375 dbus_message_unref(request_ptr
);
378 if (reply_ptr
== NULL
)
380 log_error("calling method '%s' failed, error is '%s'", method
, g_dbus_error
.message
);
381 dbus_error_free(&g_dbus_error
);
385 if (output_signature
!= NULL
)
387 reply_signature
= dbus_message_get_signature(reply_ptr
);
389 if (strcmp(reply_signature
, output_signature
) != 0)
391 log_error("reply signature is '%s' but expected signature is '%s'", reply_signature
, output_signature
);
394 dbus_message_iter_init(reply_ptr
, &iter
);
396 while (*output_signature
++ != '\0')
398 ASSERT(dbus_message_iter_get_arg_type(&iter
) != DBUS_TYPE_INVALID
); /* we've checked the signature, this should not happen */
399 parameter_ptr
= va_arg(ap
, void *);
400 dbus_message_iter_get_basic(&iter
, parameter_ptr
);
401 dbus_message_iter_next(&iter
);
404 ASSERT(dbus_message_iter_get_arg_type(&iter
) == DBUS_TYPE_INVALID
); /* we've checked the signature, this should not happen */
405 dbus_message_unref(reply_ptr
);
409 parameter_ptr
= va_arg(ap
, DBusMessage
**);
410 *(DBusMessage
**)parameter_ptr
= reply_ptr
;
422 compose_signal_match(
423 const char * service
,
428 static char rule
[1024];
429 snprintf(rule
, sizeof(rule
), "type='signal',sender='%s',path='%s',interface='%s',member='%s'", service
, object
, iface
, signal
);
433 static const char * compose_name_owner_match(const char * service
)
435 static char rule
[1024];
436 snprintf(rule
, sizeof(rule
), "type='signal',interface='"DBUS_INTERFACE_DBUS
"',member=NameOwnerChanged,arg0='%s'", service
);
441 dbus_register_object_signal_handler(
442 DBusConnection
* connection
,
443 const char * service
,
446 const char * const * signals
,
447 DBusHandleMessageFunction handler
,
450 const char * const * signal
;
452 for (signal
= signals
; *signal
!= NULL
; signal
++)
454 dbus_bus_add_match(connection
, compose_signal_match(service
, object
, iface
, *signal
), &g_dbus_error
);
455 if (dbus_error_is_set(&g_dbus_error
))
457 log_error("Failed to add D-Bus match rule: %s", g_dbus_error
.message
);
458 dbus_error_free(&g_dbus_error
);
463 dbus_connection_add_filter(g_dbus_connection
, handler
, handler_data
, NULL
);
469 dbus_unregister_object_signal_handler(
470 DBusConnection
* connection
,
471 const char * service
,
474 const char * const * signals
,
475 DBusHandleMessageFunction handler
,
478 const char * const * signal
;
480 for (signal
= signals
; *signal
!= NULL
; signal
++)
482 dbus_bus_remove_match(connection
, compose_signal_match(service
, object
, iface
, *signal
), &g_dbus_error
);
483 if (dbus_error_is_set(&g_dbus_error
))
485 log_error("Failed to remove D-Bus match rule: %s", g_dbus_error
.message
);
486 dbus_error_free(&g_dbus_error
);
491 dbus_connection_remove_filter(g_dbus_connection
, handler
, handler_data
);
497 struct dbus_signal_hook_descriptor
*
498 find_signal_hook_descriptor(
499 struct dbus_service_descriptor
* service_ptr
,
501 const char * interface
)
503 struct list_head
* node_ptr
;
504 struct dbus_signal_hook_descriptor
* hook_ptr
;
506 list_for_each(node_ptr
, &service_ptr
->hooks
)
508 hook_ptr
= list_entry(node_ptr
, struct dbus_signal_hook_descriptor
, siblings
);
509 if (strcmp(hook_ptr
->object
, object
) == 0 &&
510 strcmp(hook_ptr
->interface
, interface
) == 0)
519 #define service_ptr ((struct dbus_service_descriptor *)data)
524 DBusConnection
* connection_ptr
,
525 DBusMessage
* message_ptr
,
528 const char * object_path
;
529 const char * interface
;
530 const char * signal_name
;
531 const char * object_name
;
532 const char * old_owner
;
533 const char * new_owner
;
534 struct dbus_signal_hook_descriptor
* hook_ptr
;
535 const struct dbus_signal_hook
* signal_ptr
;
537 /* Non-signal messages are ignored */
538 if (dbus_message_get_type(message_ptr
) != DBUS_MESSAGE_TYPE_SIGNAL
)
540 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
543 interface
= dbus_message_get_interface(message_ptr
);
544 if (interface
== NULL
)
546 /* Signals with no interface are ignored */
547 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
550 object_path
= dbus_message_get_path(message_ptr
);
552 signal_name
= dbus_message_get_member(message_ptr
);
553 if (signal_name
== NULL
)
555 log_error("Received signal with NULL member");
556 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
559 log_debug("'%s' sent signal '%s'::'%s'", object_path
, interface
, signal_name
);
561 /* Handle session bus signals to track service alive state */
562 if (strcmp(interface
, DBUS_INTERFACE_DBUS
) == 0)
564 if (strcmp(signal_name
, "NameOwnerChanged") != 0)
566 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
569 if (service_ptr
->lifetime_hook_function
== NULL
)
571 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
574 //log_info("NameOwnerChanged signal received");
576 dbus_error_init(&g_dbus_error
);
577 if (!dbus_message_get_args(
580 DBUS_TYPE_STRING
, &object_name
,
581 DBUS_TYPE_STRING
, &old_owner
,
582 DBUS_TYPE_STRING
, &new_owner
,
585 log_error("Cannot get message arguments: %s", g_dbus_error
.message
);
586 dbus_error_free(&g_dbus_error
);
587 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
590 if (strcmp(object_name
, service_ptr
->service_name
) != 0)
592 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
595 if (old_owner
[0] == '\0')
597 service_ptr
->lifetime_hook_function(true);
599 else if (new_owner
[0] == '\0')
601 service_ptr
->lifetime_hook_function(false);
604 return DBUS_HANDLER_RESULT_HANDLED
;
607 /* Handle object interface signals */
608 if (object_path
!= NULL
)
610 hook_ptr
= find_signal_hook_descriptor(service_ptr
, object_path
, interface
);
611 if (hook_ptr
!= NULL
)
613 for (signal_ptr
= hook_ptr
->signal_hooks
; signal_ptr
->signal_name
!= NULL
; signal_ptr
++)
615 if (strcmp(signal_name
, signal_ptr
->signal_name
) == 0)
617 signal_ptr
->hook_function(hook_ptr
->hook_context
, message_ptr
);
618 return DBUS_HANDLER_RESULT_HANDLED
;
624 /* Let everything else pass through */
625 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
630 static struct dbus_service_descriptor
* find_service_descriptor(const char * service_name
)
632 struct list_head
* node_ptr
;
633 struct dbus_service_descriptor
* descr_ptr
;
635 list_for_each(node_ptr
, &g_dbus_services
)
637 descr_ptr
= list_entry(node_ptr
, struct dbus_service_descriptor
, siblings
);
638 if (strcmp(descr_ptr
->service_name
, service_name
) == 0)
647 static struct dbus_service_descriptor
* find_or_create_service_descriptor(const char * service_name
)
649 struct dbus_service_descriptor
* descr_ptr
;
651 descr_ptr
= find_service_descriptor(service_name
);
652 if (descr_ptr
!= NULL
)
657 descr_ptr
= malloc(sizeof(struct dbus_service_descriptor
));
658 if (descr_ptr
== NULL
)
660 log_error("malloc() failed to allocate struct dbus_service_descriptor");
664 descr_ptr
->service_name
= strdup(service_name
);
665 if (descr_ptr
->service_name
== NULL
)
667 log_error("strdup() failed for service name '%s'", service_name
);
672 descr_ptr
->lifetime_hook_function
= NULL
;
673 INIT_LIST_HEAD(&descr_ptr
->hooks
);
675 list_add_tail(&descr_ptr
->siblings
, &g_dbus_services
);
677 dbus_connection_add_filter(g_dbus_connection
, dbus_signal_handler
, descr_ptr
, NULL
);
682 static void free_service_descriptor_if_empty(struct dbus_service_descriptor
* service_ptr
)
684 if (service_ptr
->lifetime_hook_function
!= NULL
)
689 if (!list_empty(&service_ptr
->hooks
))
694 dbus_connection_remove_filter(g_dbus_connection
, dbus_signal_handler
, service_ptr
);
696 list_del(&service_ptr
->siblings
);
697 free(service_ptr
->service_name
);
702 dbus_register_object_signal_hooks(
703 DBusConnection
* connection
,
704 const char * service_name
,
708 const struct dbus_signal_hook
* signal_hooks
)
710 struct dbus_service_descriptor
* service_ptr
;
711 struct dbus_signal_hook_descriptor
* hook_ptr
;
712 const struct dbus_signal_hook
* signal_ptr
;
714 if (connection
!= g_dbus_connection
)
716 log_error("multiple connections are not implemented yet");
721 service_ptr
= find_or_create_service_descriptor(service_name
);
722 if (service_ptr
== NULL
)
724 log_error("find_or_create_service_descriptor() failed.");
728 hook_ptr
= find_signal_hook_descriptor(service_ptr
, object
, iface
);
729 if (hook_ptr
!= NULL
)
731 log_error("refusing to register two signal monitors for '%s':'%s':'%s'", service_name
, object
, iface
);
733 goto maybe_free_service
;
736 hook_ptr
= malloc(sizeof(struct dbus_signal_hook_descriptor
));
737 if (hook_ptr
== NULL
)
739 log_error("malloc() failed to allocate struct dbus_signal_hook_descriptor");
740 goto maybe_free_service
;
743 hook_ptr
->object
= strdup(object
);
744 if (hook_ptr
->object
== NULL
)
746 log_error("strdup() failed for object name");
750 hook_ptr
->interface
= strdup(iface
);
751 if (hook_ptr
->interface
== NULL
)
753 log_error("strdup() failed for interface name");
754 goto free_object_name
;
757 hook_ptr
->hook_context
= hook_context
;
758 hook_ptr
->signal_hooks
= signal_hooks
;
760 list_add_tail(&hook_ptr
->siblings
, &service_ptr
->hooks
);
762 for (signal_ptr
= signal_hooks
; signal_ptr
->signal_name
!= NULL
; signal_ptr
++)
764 dbus_bus_add_match(connection
, compose_signal_match(service_name
, object
, iface
, signal_ptr
->signal_name
), &g_dbus_error
);
765 if (dbus_error_is_set(&g_dbus_error
))
767 log_error("Failed to add D-Bus match rule: %s", g_dbus_error
.message
);
768 dbus_error_free(&g_dbus_error
);
770 while (signal_ptr
!= signal_hooks
)
772 ASSERT(signal_ptr
> signal_hooks
);
775 dbus_bus_remove_match(connection
, compose_signal_match(service_name
, object
, iface
, signal_ptr
->signal_name
), &g_dbus_error
);
776 if (dbus_error_is_set(&g_dbus_error
))
778 log_error("Failed to remove D-Bus match rule: %s", g_dbus_error
.message
);
779 dbus_error_free(&g_dbus_error
);
790 list_del(&hook_ptr
->siblings
);
791 free(hook_ptr
->interface
);
793 free(hook_ptr
->object
);
797 free_service_descriptor_if_empty(service_ptr
);
803 dbus_unregister_object_signal_hooks(
804 DBusConnection
* connection
,
805 const char * service_name
,
809 struct dbus_service_descriptor
* service_ptr
;
810 struct dbus_signal_hook_descriptor
* hook_ptr
;
811 const struct dbus_signal_hook
* signal_ptr
;
813 if (connection
!= g_dbus_connection
)
815 log_error("multiple connections are not implemented yet");
820 service_ptr
= find_service_descriptor(service_name
);
821 if (service_ptr
== NULL
)
823 log_error("find_service_descriptor() failed.");
828 hook_ptr
= find_signal_hook_descriptor(service_ptr
, object
, iface
);
829 if (hook_ptr
== NULL
)
831 log_error("cannot unregister non-existing signal monitor for '%s':'%s':'%s'", service_name
, object
, iface
);
836 for (signal_ptr
= hook_ptr
->signal_hooks
; signal_ptr
->signal_name
!= NULL
; signal_ptr
++)
838 dbus_bus_remove_match(connection
, compose_signal_match(service_name
, object
, iface
, signal_ptr
->signal_name
), &g_dbus_error
);
839 if (dbus_error_is_set(&g_dbus_error
))
841 if (dbus_error_is_set(&g_dbus_error
))
843 log_error("Failed to remove D-Bus match rule: %s", g_dbus_error
.message
);
844 dbus_error_free(&g_dbus_error
);
849 list_del(&hook_ptr
->siblings
);
851 free(hook_ptr
->interface
);
852 free(hook_ptr
->object
);
855 free_service_descriptor_if_empty(service_ptr
);
859 dbus_register_service_lifetime_hook(
860 DBusConnection
* connection
,
861 const char * service_name
,
862 void (* hook_function
)(bool appeared
))
864 struct dbus_service_descriptor
* service_ptr
;
866 if (connection
!= g_dbus_connection
)
868 log_error("multiple connections are not implemented yet");
873 service_ptr
= find_or_create_service_descriptor(service_name
);
874 if (service_ptr
== NULL
)
876 log_error("find_or_create_service_descriptor() failed.");
880 if (service_ptr
->lifetime_hook_function
!= NULL
)
882 log_error("cannot register two lifetime hooks for '%s'", service_name
);
884 goto maybe_free_service
;
887 service_ptr
->lifetime_hook_function
= hook_function
;
889 dbus_bus_add_match(connection
, compose_name_owner_match(service_name
), &g_dbus_error
);
890 if (dbus_error_is_set(&g_dbus_error
))
892 log_error("Failed to add D-Bus match rule: %s", g_dbus_error
.message
);
893 dbus_error_free(&g_dbus_error
);
900 service_ptr
->lifetime_hook_function
= NULL
;
902 free_service_descriptor_if_empty(service_ptr
);
908 dbus_unregister_service_lifetime_hook(
909 DBusConnection
* connection
,
910 const char * service_name
)
912 struct dbus_service_descriptor
* service_ptr
;
914 if (connection
!= g_dbus_connection
)
916 log_error("multiple connections are not implemented yet");
921 service_ptr
= find_service_descriptor(service_name
);
922 if (service_ptr
== NULL
)
924 log_error("find_service_descriptor() failed.");
928 if (service_ptr
->lifetime_hook_function
== NULL
)
930 log_error("cannot unregister non-existent lifetime hook for '%s'", service_name
);
935 service_ptr
->lifetime_hook_function
= NULL
;
937 dbus_bus_remove_match(connection
, compose_name_owner_match(service_name
), &g_dbus_error
);
938 if (dbus_error_is_set(&g_dbus_error
))
940 log_error("Failed to remove D-Bus match rule: %s", g_dbus_error
.message
);
941 dbus_error_free(&g_dbus_error
);
944 free_service_descriptor_if_empty(service_ptr
);