From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Calderon Subject: Patch for x11idle Date: Wed, 18 Jul 2012 16:39:55 -0400 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Return-path: Received: from eggs.gnu.org ([208.118.235.92]:41965) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Srb2f-0005mH-MF for emacs-orgmode@gnu.org; Wed, 18 Jul 2012 16:40:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Srb2e-0000Ff-RS for emacs-orgmode@gnu.org; Wed, 18 Jul 2012 16:40:17 -0400 Received: from mail-ob0-f169.google.com ([209.85.214.169]:45803) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Srb2e-0000FU-MP for emacs-orgmode@gnu.org; Wed, 18 Jul 2012 16:40:16 -0400 Received: by obhx4 with SMTP id x4so3338520obh.0 for ; Wed, 18 Jul 2012 13:40:16 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org >From c4856a35a2118efb16d6b8eb674ff9e05fc7f65a Mon Sep 17 00:00:00 2001 From: Nicolas Calderon Asselin 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