Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 79945431FAE for ; Sat, 21 Nov 2009 16:33:27 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uuiL7mpWFeIq for ; Sat, 21 Nov 2009 16:33:26 -0800 (PST) Received: from orsmga101.jf.intel.com (mga06.intel.com [134.134.136.21]) by olra.theworths.org (Postfix) with ESMTP id 133B8431FBC for ; Sat, 21 Nov 2009 16:33:25 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 21 Nov 2009 16:33:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.47,265,1257148800"; d="scan'208";a="571886901" Received: from unknown (HELO localhost.localdomain) ([10.255.16.190]) by orsmga001.jf.intel.com with ESMTP; 21 Nov 2009 16:33:13 -0800 From: Chris Wilson To: notmuch@notmuchmail.org Date: Sun, 22 Nov 2009 00:33:19 +0000 Message-Id: <1258849999-27513-1-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 1.6.5.3 In-Reply-To: <1258849350-27213-1-git-send-email-chris@chris-wilson.co.uk> References: <1258849350-27213-1-git-send-email-chris@chris-wilson.co.uk> Subject: [notmuch] [PATCH] notmuch-new: Only install SIGALRM if not running under gdb X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Nov 2009 00:33:27 -0000 I felt sorry for Carl trying to step through an exception from xapian and suffering from the SIGALARMs.. We can detect if the user launched notmuch under a debugger by either checking our cmdline for the presence of the gdb string or querying if valgrind is controlling our process. For the latter we need to add a compile time check for the valgrind development library, and so add the initial support to build Makefile.config from configure. Signed-off-by: Chris Wilson Reviewed-by: Carl Worth [ickle: And do not install the timer] --- Makefile.config | 1 + Makefile.local | 3 ++- configure | 21 +++++++++++++++++---- debugger.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ notmuch-client.h | 3 +++ notmuch-new.c | 12 +++++++----- 6 files changed, 77 insertions(+), 10 deletions(-) create mode 100644 debugger.c diff --git a/Makefile.config b/Makefile.config index d72a39e..ddc7436 100644 --- a/Makefile.config +++ b/Makefile.config @@ -1,2 +1,3 @@ prefix = /usr/local bash_completion_dir = /etc/bash_completion.d +CFLAGS += -DHAVE_VALGRIND diff --git a/Makefile.local b/Makefile.local index 3c99624..efe76c8 100644 --- a/Makefile.local +++ b/Makefile.local @@ -3,6 +3,8 @@ all: notmuch notmuch.1.gz emacs: notmuch.elc notmuch_client_srcs = \ + debugger.c \ + gmime-filter-reply.c \ notmuch.c \ notmuch-config.c \ notmuch-dump.c \ @@ -14,7 +16,6 @@ notmuch_client_srcs = \ notmuch-show.c \ notmuch-tag.c \ notmuch-time.c \ - gmime-filter-reply.c \ query-string.c \ show-message.c diff --git a/configure b/configure index fe46c8e..b4770ec 100755 --- a/configure +++ b/configure @@ -53,6 +53,14 @@ else errors=$((errors + 1)) fi +if pkg-config --modversion valgrind > /dev/null 2>&1; then + echo "Checking for valgrind development files... Yes." + have_valgrind=-DHAVE_VALGRIND +else + echo "Checking for valgrind development files... No." + have_valgrind= +fi + if [ $errors -gt 0 ]; then cat < Makefile.config < + */ + +#include "notmuch-client.h" + +#include + +#if HAVE_VALGRIND +#include +#else +#define RUNNING_ON_VALGRIND 0 +#endif + +notmuch_bool_t +debugger_is_active (void) +{ + char buf[1024]; + + if (RUNNING_ON_VALGRIND) + return TRUE; + + sprintf (buf, "/proc/%d/exe", getppid ()); + if (readlink (buf, buf, sizeof (buf)) != -1 && + strncmp (basename (buf), "gdb", 3) == 0) + { + return TRUE; + } + + return FALSE; +} diff --git a/notmuch-client.h b/notmuch-client.h index b65aa77..ea77686 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -179,4 +179,7 @@ notmuch_config_set_user_other_email (notmuch_config_t *config, const char *other_email[], size_t length); +notmuch_bool_t +debugger_is_active (void); + #endif diff --git a/notmuch-new.c b/notmuch-new.c index 43cc4fb..18ba2bd 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -272,11 +272,13 @@ add_files (notmuch_database_t *notmuch, } /* Setup our handler for SIGALRM */ - memset (&action, 0, sizeof (struct sigaction)); - action.sa_handler = handle_sigalrm; - sigemptyset (&action.sa_mask); - action.sa_flags = SA_RESTART; - sigaction (SIGALRM, &action, NULL); + if (! debugger_is_active ()) { + memset (&action, 0, sizeof (struct sigaction)); + action.sa_handler = handle_sigalrm; + sigemptyset (&action.sa_mask); + action.sa_flags = SA_RESTART; + sigaction (SIGALRM, &action, NULL); + } /* Then start a timer to send SIGALRM once per second. */ timerval.it_interval.tv_sec = 1; -- 1.6.5.3