Commit 55a79968 authored by Christian Hergert's avatar Christian Hergert
Browse files

upower: cleanup system bus connection when context is released

This helps ensure that we release the upower connection when we close
our last context. Otherwise, we can get into a state where exit-on-close
will kill our process.

When that happens, we fail to save all of our file state, which is very
much a bad thing.
parent 11c1bac7
......@@ -24,6 +24,7 @@
static GDBusProxy *gUPowerProxy;
static GDBusProxy *gUPowerDeviceProxy;
static gint gUPowerHold;
G_LOCK_DEFINE_STATIC (proxy_lock);
......@@ -152,3 +153,31 @@ ide_battery_monitor_get_should_conserve (void)
return should_conserve;
}
void
_ide_battery_monitor_shutdown (void)
{
G_LOCK (proxy_lock);
if (--gUPowerHold == 0)
{
g_clear_object (&gUPowerProxy);
g_clear_object (&gUPowerDeviceProxy);
}
G_UNLOCK (proxy_lock);
}
void
_ide_battery_monitor_init (void)
{
g_autoptr(GDBusProxy) proxy = NULL;
g_autoptr(GDBusProxy) device_proxy = NULL;
G_LOCK (proxy_lock);
gUPowerHold++;
G_UNLOCK (proxy_lock);
proxy = ide_battery_monitor_get_proxy ();
device_proxy = ide_battery_monitor_get_device_proxy ();
}
......@@ -542,6 +542,8 @@ ide_context_finalize (GObject *object)
G_OBJECT_CLASS (ide_context_parent_class)->finalize (object);
_ide_battery_monitor_shutdown ();
IDE_EXIT;
}
......@@ -746,6 +748,8 @@ ide_context_init (IdeContext *self)
IDE_ENTRY;
_ide_battery_monitor_init ();
self->recent_manager = g_object_ref (gtk_recent_manager_get_default ());
self->root_build_dir = g_build_filename (g_get_user_cache_dir (),
......
......@@ -51,6 +51,8 @@ gboolean _ide_back_forward_list_save_finish (IdeBackForwardList *s
GError **error);
IdeBackForwardItem *_ide_back_forward_list_find (IdeBackForwardList *self,
IdeFile *file);
void _ide_battery_monitor_init (void);
void _ide_battery_monitor_shutdown (void);
void _ide_buffer_set_changed_on_volume (IdeBuffer *self,
gboolean changed_on_volume);
gboolean _ide_buffer_get_loading (IdeBuffer *self);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment