[gnome-settings-daemon/gnome-3-2] power: Don't crash when setting the dim timeout when using NX



commit f104ff492e1b4b414864307edd233552215da8f2
Author: Richard Hughes <richard hughsie com>
Date:   Fri Oct 7 10:35:08 2011 +0100

    power: Don't crash when setting the dim timeout when using NX
    
    We're querying a timer that doesn't exist, plus we're not even catching the X
    error. Fix both.
    
    Resolves https://bugzilla.gnome.org/show_bug.cgi?id=661000

 plugins/power/gpm-idletime.c      |   10 ++++++++++
 plugins/power/gsd-power-manager.c |    2 ++
 2 files changed, 12 insertions(+), 0 deletions(-)
---
diff --git a/plugins/power/gpm-idletime.c b/plugins/power/gpm-idletime.c
index 61380ba..215bdd1 100644
--- a/plugins/power/gpm-idletime.c
+++ b/plugins/power/gpm-idletime.c
@@ -80,13 +80,23 @@ gpm_idletime_xsyncvalue_to_int64 (XSyncValue value)
                 (guint64) XSyncValueLow32 (value);
 }
 
+/* gets the IDLETIME counter value, or 0 for invalid */
 gint64
 gpm_idletime_get_time (GpmIdletime *idletime)
 {
         XSyncValue value;
+
+        /* we don't have IDLETIME support */
+        if (!idletime->priv->idle_counter)
+                return 0;
+
+        /* NX explodes if you query the counter */
+        gdk_error_trap_push ();
         XSyncQueryCounter (idletime->priv->dpy,
                            idletime->priv->idle_counter,
                            &value);
+        if (gdk_error_trap_pop ())
+                return 0;
         return gpm_idletime_xsyncvalue_to_int64 (value);
 }
 
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index e648a11..3076088 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -2998,6 +2998,8 @@ idle_set_timeout_dim (GsdPowerManager *manager, guint timeout)
         guint timeout_adjusted;
 
         idle_time_in_msec = gpm_idletime_get_time (manager->priv->idletime);
+        if (idle_time_in_msec == 0)
+                return FALSE;
         timeout_adjusted  = idle_adjust_timeout_dim (idle_time_in_msec / 1000, timeout);
         g_debug ("Current idle time=%lldms, timeout was %us, becomes %us after adjustment",
                    (long long int)idle_time_in_msec, timeout, timeout_adjusted);



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