ソースを参照

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
Nicolas Calderon Asselin 13 年 前
コミット
49994a4c3e
1 ファイル変更15 行追加4 行削除
  1. 15 4
      UTILITIES/x11idle.c

+ 15 - 4
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;
 }
+