- DBusConnection *c;
-
- bus_done_api(m);
- bus_done_system(m);
- bus_done_private(m);
-
- while ((c = set_steal_first(m->bus_connections)))
- shutdown_connection(m, c);
-
- while ((c = set_steal_first(m->bus_connections_for_dispatch)))
- shutdown_connection(m, c);
-
- set_free(m->bus_connections);
- set_free(m->bus_connections_for_dispatch);
-
- if (m->name_data_slot >= 0)
- dbus_pending_call_free_data_slot(&m->name_data_slot);
-
- if (m->conn_data_slot >= 0)
- dbus_pending_call_free_data_slot(&m->conn_data_slot);
-
- if (m->subscribed_data_slot >= 0)
- dbus_connection_free_data_slot(&m->subscribed_data_slot);
-}
-
-static void query_pid_pending_cb(DBusPendingCall *pending, void *userdata) {
- Manager *m = userdata;
- DBusMessage *reply;
- DBusError error;
- const char *name;
-
- dbus_error_init(&error);
-
- assert_se(name = BUS_PENDING_CALL_NAME(m, pending));
- assert_se(reply = dbus_pending_call_steal_reply(pending));
-
- switch (dbus_message_get_type(reply)) {
-
- case DBUS_MESSAGE_TYPE_ERROR:
-
- assert_se(dbus_set_error_from_message(&error, reply));
- log_warning("GetConnectionUnixProcessID() failed: %s", bus_error_message(&error));
- break;
-
- case DBUS_MESSAGE_TYPE_METHOD_RETURN: {
- uint32_t r;
-
- if (!dbus_message_get_args(reply,
- &error,
- DBUS_TYPE_UINT32, &r,
- DBUS_TYPE_INVALID)) {
- log_error("Failed to parse GetConnectionUnixProcessID() reply: %s", bus_error_message(&error));
- break;
- }
-
- manager_dispatch_bus_query_pid_done(m, name, (pid_t) r);
- break;
- }
-
- default:
- assert_not_reached("Invalid reply message");
- }
-
- dbus_message_unref(reply);
- dbus_error_free(&error);
-}
-
-int bus_query_pid(Manager *m, const char *name) {
- DBusMessage *message = NULL;
- DBusPendingCall *pending = NULL;
- char *n = NULL;
-
- assert(m);
- assert(name);
-
- if (!(message = dbus_message_new_method_call(
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS,
- "GetConnectionUnixProcessID")))
- goto oom;
-
- if (!(dbus_message_append_args(
- message,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_INVALID)))
- goto oom;
-
- if (!dbus_connection_send_with_reply(m->api_bus, message, &pending, -1))
- goto oom;
-
- if (!(n = strdup(name)))
- goto oom;
-
- if (!dbus_pending_call_set_data(pending, m->name_data_slot, n, free))
- goto oom;
-
- n = NULL;
-
- if (!dbus_pending_call_set_notify(pending, query_pid_pending_cb, m, NULL))
- goto oom;
-
- dbus_message_unref(message);
- dbus_pending_call_unref(pending);
-
- return 0;
-
-oom:
- free(n);
-
- if (pending) {
- dbus_pending_call_cancel(pending);
- dbus_pending_call_unref(pending);
- }
-
- if (message)
- dbus_message_unref(message);
-
- return -ENOMEM;
-}
-
-int bus_broadcast(Manager *m, DBusMessage *message) {
- bool oom = false;
- Iterator i;
- DBusConnection *c;
-
- assert(m);
- assert(message);
-
- SET_FOREACH(c, m->bus_connections_for_dispatch, i)
- if (c != m->system_bus || m->running_as == SYSTEMD_SYSTEM)
- oom = !dbus_connection_send(c, message, NULL);
-
- SET_FOREACH(c, m->bus_connections, i)
- if (c != m->system_bus || m->running_as == SYSTEMD_SYSTEM)
- oom = !dbus_connection_send(c, message, NULL);
-
- return oom ? -ENOMEM : 0;
-}
-
-bool bus_has_subscriber(Manager *m) {
- Iterator i;
- DBusConnection *c;