device: don't attempt to export if bus connection has been lost

E.g. if aborting the initialization sequence.
This commit is contained in:
Aleksander Morgado
2024-09-30 11:07:18 +00:00
committed by Aleksander Morgado
parent dfc0f8ebfd
commit a16ad2757d
+14 -10
View File
@@ -348,8 +348,9 @@ unexport_modem (MMDevice *self)
static void
export_modem (MMDevice *self)
{
GDBusConnection *connection = NULL;
gchar *path;
g_autoptr(GDBusConnection) connection = NULL;
g_autofree gchar *existing_path = NULL;
g_autofree gchar *path = NULL;
g_assert (MM_IS_BASE_MODEM (self->priv->modem));
g_assert (G_IS_DBUS_OBJECT_MANAGER (self->priv->object_manager));
@@ -360,12 +361,20 @@ export_modem (MMDevice *self)
return;
}
/* Don't export if we've aborted initialization */
g_object_get (self->priv->object_manager,
"connection", &connection,
NULL);
if (!connection) {
mm_obj_dbg (self, "exporting aborted as there is no bus connection");
return;
}
/* Don't export already exported modems */
g_object_get (self->priv->modem,
"g-object-path", &path,
"g-object-path", &existing_path,
NULL);
if (path) {
g_free (path);
if (existing_path) {
mm_obj_dbg (self, "modem already exported");
return;
}
@@ -373,9 +382,6 @@ export_modem (MMDevice *self)
/* No outstanding port tasks, so if the modem is valid we can export it */
path = g_strdup_printf (MM_DBUS_MODEM_PREFIX "/%d", mm_base_modem_get_dbus_id (self->priv->modem));
g_object_get (self->priv->object_manager,
"connection", &connection,
NULL);
g_object_set (self->priv->modem,
"g-object-path", path,
MM_BASE_MODEM_CONNECTION, connection,
@@ -395,8 +401,6 @@ export_modem (MMDevice *self)
(mm_base_modem_get_subsystem_vendor_id (self->priv->modem) & 0xFFFF));
if (self->priv->virtual)
mm_obj_dbg (self, " virtual");
g_free (path);
}
/*****************************************************************************/