emacs-orgmode
[Top][All Lists]
Advanced

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

[O] Patch for x11idle


From: Nicolas Calderon
Subject: [O] Patch for x11idle
Date: Wed, 18 Jul 2012 16:39:55 -0400

>From c4856a35a2118efb16d6b8eb674ff9e05fc7f65a Mon Sep 17 00:00:00 2001
From: Nicolas Calderon Asselin <address@hidden>
Date: Wed, 18 Jul 2012 14:19:10 -0400
Subject: [PATCH 1/2] Made x11idle more robust

* UTILITIES/x11idle.c (org-clock-idle-time): Added multiple checks to
  functions return values to prevent segfault. Also "fixed" return codes
  to fail unless the value could be printed, in which case the program
  succeeds.

TINYCHANGE
---
 UTILITIES/x11idle.c |   19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/UTILITIES/x11idle.c b/UTILITIES/x11idle.c
index 33d0035..8d54468 100644
--- a/UTILITIES/x11idle.c
+++ b/UTILITIES/x11idle.c
@@ -8,14 +8,25 @@
  * path
  */
 main() {
+    Status querry = 0;
     XScreenSaverInfo *info = XScreenSaverAllocInfo();
+    //open the display specified by the DISPLAY environment variable
     Display *display = XOpenDisplay(0);

-    //check that X11 is running or else you get a segafult/coredump
-    if (display != NULL) {
-       XScreenSaverQueryInfo(display, DefaultRootWindow(display), info);
+    //display could be null if there is no X server running
+    if (info == NULL || display == NULL) {
+    return -1;
     }
-    XScreenSaverQueryInfo(display, DefaultRootWindow(display), info);
+
+    //X11 is running, retrieve and print idle time
+       querry = XScreenSaverQueryInfo(display, DefaultRootWindow(display), 
info);
+
+    if (querry == 0) {
+    return -1;
+    }
+
+    //idle time was retrieved successfully, print it
     printf("%u\n", info->idle);
     return 0;
 }
+
-- 
1.7.10.4



reply via email to

[Prev in Thread] Current Thread [Next in Thread]