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
This commit is contained in:
Nicolas Calderon Asselin 2012-07-18 14:19:10 -04:00 committed by Bastien Guerry
parent 12a53c7161
commit 49994a4c3e
1 changed files with 15 additions and 4 deletions

View File

@ -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;
}