From d0a15d1f22b9c480b9630551af91103e30e38e29 Mon Sep 17 00:00:00 2001 From: mcc45tr Date: Wed, 2 Sep 2026 16:22:28 +0300 Subject: [PATCH] iio-sensor-proxy: discover sensors before owning D-Bus name --- src/iio-sensor-proxy.c | 90 +++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 46 deletions(-) diff --git a/src/iio-sensor-proxy.c b/src/iio-sensor-proxy.c index cbd4463..b785703 100644 --- a/src/iio-sensor-proxy.c +++ b/src/iio-sensor-proxy.c @@ -723,6 +723,46 @@ bus_acquired_handler (GDBusConnection *connection, }; guint i; + /* + * Finish initial discovery before returning from the bus-acquired + * callback. g_bus_own_name() only requests the well-known name after this + * callback returns, so clients cannot cache Has* = false while the initial + * sensors are still being opened. + */ + data->client = g_udev_client_new (subsystems); + + for (i = 0; i < NUM_SENSOR_TYPES; i++) { + data->clients[i] = create_clients_hash_table (); + data->sensor_startup_dbus_invocations_delayed[i] = g_ptr_array_new (); + } + + data->connection = g_object_ref (connection); + + g_signal_connect (G_OBJECT (data->client), "uevent", + G_CALLBACK (sensor_changes), data); + + if (find_sensors (data->client, data)) { + for (i = 0; i < NUM_SENSOR_TYPES; i++) { + SensorDevice *sensor_device; + + if (!driver_type_exists (data, i)) + continue; + + sensor_device = driver_open (DRIVER_FOR_TYPE(i), UDEV_DEVICE_FOR_TYPE(i), + driver_type_to_callback_func (data->drivers[i]->type), data); + if (!sensor_device) { + DRIVER_FOR_TYPE(i) = NULL; + g_clear_object (&UDEV_DEVICE_FOR_TYPE(i)); + continue; + } + + DEVICE_FOR_TYPE(i) = sensor_device; + } + } + + if (!any_sensors_left (data)) + g_message ("No sensors or missing kernel drivers for the sensors. Waiting for hotplug sensors"); + g_dbus_connection_register_object (connection, SENSOR_PROXY_DBUS_PATH, data->introspection_data->interfaces[0], @@ -738,14 +778,6 @@ bus_acquired_handler (GDBusConnection *connection, data, NULL, NULL); - - /* Initialize DBus clients hash table before DBus is fully exposed */ - data->client = g_udev_client_new (subsystems); - - for (guint i = 0; i < NUM_SENSOR_TYPES; i++) - data->clients[i] = create_clients_hash_table (); - - data->connection = g_object_ref (connection); } static void @@ -753,44 +785,10 @@ name_acquired_handler (GDBusConnection *connection, const gchar *name, gpointer user_data) { - SensorData *data = user_data; - guint i; - - if (!find_sensors (data->client, data)) - goto bail; - - g_signal_connect (G_OBJECT (data->client), "uevent", - G_CALLBACK (sensor_changes), data); - - for (i = 0; i < NUM_SENSOR_TYPES; i++) { - SensorDevice *sensor_device; - - data->sensor_startup_dbus_invocations_delayed[i] = g_ptr_array_new (); - - if (!driver_type_exists (data, i)) - continue; - - sensor_device = driver_open (DRIVER_FOR_TYPE(i), UDEV_DEVICE_FOR_TYPE(i), - driver_type_to_callback_func (data->drivers[i]->type), data); - if (!sensor_device) { - DRIVER_FOR_TYPE(i) = NULL; - g_clear_object (&UDEV_DEVICE_FOR_TYPE(i)); - continue; - } - - DEVICE_FOR_TYPE(i) = sensor_device; - } - - if (!any_sensors_left (data)) - goto bail; - - send_dbus_event (data, PROP_ALL); - send_dbus_event (data, PROP_ALL_COMPASS); - return; - -bail: - data->ret = 0; - g_message ("No sensors or missing kernel drivers for the sensors. Waiting for hotplug sensors"); + /* Initial sensor state is complete before the name becomes visible. */ + (void) connection; + (void) name; + (void) user_data; } static gboolean -- 2.55.0