From: Nicolas Calderon <nicolas.calderon.asselin@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Patch for x11idle
Date: Wed, 18 Jul 2012 16:39:55 -0400 [thread overview]
Message-ID: <CAHbMD+FcZWP4Yw-wxeYu_mfeVPcRrSsy655xk3wb6PhgNH81xw@mail.gmail.com> (raw)
From c4856a35a2118efb16d6b8eb674ff9e05fc7f65a Mon Sep 17 00:00:00 2001
From: Nicolas Calderon Asselin <nicolas.calderon.asselin@gmail.com>
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
next reply other threads:[~2012-07-18 20:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-18 20:39 Nicolas Calderon [this message]
2012-07-24 15:09 ` Patch for x11idle Bastien
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAHbMD+FcZWP4Yw-wxeYu_mfeVPcRrSsy655xk3wb6PhgNH81xw@mail.gmail.com \
--to=nicolas.calderon.asselin@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).