[gnome-session/gnome-3-6] systemd: Drop system inhibitor when necessary



commit 048fd0971ac11ff8544c53acad0e8f1c85e3aadf
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Oct 22 21:06:24 2012 -0400

    systemd: Drop system inhibitor when necessary
    
    We need to be careful here, since we are getting the system
    inhibitor with an async call. By the time we get the reply,
    the session inhibitor may have already been dropped again.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=685499

 gnome-session/gsm-systemd.c |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)
---
diff --git a/gnome-session/gsm-systemd.c b/gnome-session/gsm-systemd.c
index a8597b2..345c345 100644
--- a/gnome-session/gsm-systemd.c
+++ b/gnome-session/gsm-systemd.c
@@ -66,6 +66,15 @@ G_DEFINE_TYPE_WITH_CODE (GsmSystemd, gsm_systemd, G_TYPE_OBJECT,
                          G_IMPLEMENT_INTERFACE (GSM_TYPE_SYSTEM,
                                                 gsm_systemd_system_init))
 
+static void
+drop_system_inhibitor (GsmSystemd *manager)
+{
+        if (manager->priv->inhibit_fd != -1) {
+                g_debug ("Dropping system inhibitor");
+                close (manager->priv->inhibit_fd);
+                manager->priv->inhibit_fd = -1;
+        }
+}
 
 static void
 gsm_systemd_finalize (GObject *object)
@@ -78,8 +87,8 @@ gsm_systemd_finalize (GObject *object)
 
         if (systemd->priv->inhibitors != NULL) {
                 g_slist_free_full (systemd->priv->inhibitors, g_free);
-                close (systemd->priv->inhibit_fd);
         }
+        drop_system_inhibitor (systemd);
 
         G_OBJECT_CLASS (gsm_systemd_parent_class)->finalize (object);
 }
@@ -107,6 +116,8 @@ gsm_systemd_init (GsmSystemd *manager)
                                                      GSM_TYPE_SYSTEMD,
                                                      GsmSystemdPrivate);
 
+        manager->priv->inhibit_fd = -1;
+
         error = NULL;
 
         bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
@@ -531,6 +542,10 @@ inhibit_done (GObject      *source,
                 g_object_unref (fd_list);
                 g_variant_unref (res);
         }
+
+        if (manager->priv->inhibitors == NULL) {
+                drop_system_inhibitor (manager);
+        }
 }
 
 static void
@@ -576,9 +591,7 @@ gsm_systemd_remove_inhibitor (GsmSystem   *system,
         g_free (l->data);
         manager->priv->inhibitors = g_slist_delete_link (manager->priv->inhibitors, l);
         if (manager->priv->inhibitors == NULL) {
-                        g_debug ("Dropping system inhibitor");
-                        close (manager->priv->inhibit_fd);
-                        manager->priv->inhibit_fd = -1;
+                drop_system_inhibitor (manager);
         }
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]