Skip to content
Snippets Groups Projects
Commit 0329b291 authored by Manu Barrio Linares's avatar Manu Barrio Linares Committed by Gaël Bonithon
Browse files

Remove all lingering Inhibitors when DBus connection is lost

Fixes: #248
parent 9db37016
No related branches found
No related tags found
1 merge request!81Remove all lingering Inhibitors when DBus connection is lost
Pipeline #32606 passed with stages
in 6 minutes and 33 seconds
......@@ -153,24 +153,6 @@ xfpm_inhibit_find_application_by_cookie (XfpmInhibit *inhibit,
return NULL;
}
static Inhibitor *
xfpm_inhibit_find_application_by_unique_connection_name (XfpmInhibit *inhibit,
const gchar *unique_name)
{
guint i;
Inhibitor *inhibitor;
for (i = 0; i < inhibit->priv->array->len; i++)
{
inhibitor = g_ptr_array_index (inhibit->priv->array, i);
if (g_strcmp0 (inhibitor->unique_name, unique_name) == 0)
{
return inhibitor;
}
}
return NULL;
}
static gboolean
xfpm_inhibit_remove_application_by_cookie (XfpmInhibit *inhibit,
guint cookie)
......@@ -195,19 +177,26 @@ xfpm_inhibit_connection_lost_cb (XfpmDBusMonitor *monitor,
XfpmInhibit *inhibit)
{
Inhibitor *inhibitor;
gboolean changed = FALSE;
if (!on_session)
return;
inhibitor = xfpm_inhibit_find_application_by_unique_connection_name (inhibit, unique_name);
if (inhibitor)
// Traverse in reverse to safely delete array elements without shifting issues
for (guint i = inhibit->priv->array->len - 1; i != -1U; i--)
{
XFPM_DEBUG ("Application=%s with unique connection name=%s disconnected",
inhibitor->app_name, inhibitor->unique_name);
xfpm_inhibit_free_inhibitor (inhibit, inhibitor);
xfpm_inhibit_has_inhibit_changed (inhibit);
inhibitor = g_ptr_array_index (inhibit->priv->array, i);
if (g_strcmp0 (inhibitor->unique_name, unique_name) == 0)
{
XFPM_DEBUG ("Application=%s with unique connection name=%s disconnected",
inhibitor->app_name, inhibitor->unique_name);
xfpm_inhibit_free_inhibitor (inhibit, inhibitor);
changed = TRUE;
}
}
if (changed)
xfpm_inhibit_has_inhibit_changed (inhibit);
}
static void
......@@ -413,7 +402,7 @@ xfpm_inhibit_un_inhibit (XfpmInhibit *inhibit,
guint IN_cookie,
gpointer user_data)
{
XFPM_DEBUG ("UnHibit message received");
XFPM_DEBUG ("Uninhibit message received");
if (!xfpm_inhibit_remove_application_by_cookie (inhibit, IN_cookie))
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment