summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Calderon Asselin <nicolas.calderon.asselin@gmail.com>2012-07-18 14:19:10 -0400
committerBastien Guerry <bzg@altern.org>2012-07-24 17:08:33 +0200
commit49994a4c3effc1327a96ed54a23f2174b4077cb8 (patch)
treeb83333aaecc3468b297f1e1776b7d316f615fa1c
parent12a53c716189d142333e26b14e6ad836fbc70b35 (diff)
downloadorg-mode-49994a4c3effc1327a96ed54a23f2174b4077cb8.tar.gz
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
-rw-r--r--UTILITIES/x11idle.c19
1 files 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;
}
+