[notmuch] [PATCH 1/2] notmuch-new: Only install SIGALRM if not running under gdb
authorChris Wilson <chris@chris-wilson.co.uk>
Sun, 22 Nov 2009 00:44:31 +0000 (00:44 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:35:38 +0000 (09:35 -0800)
ca/677015fd9cf9e31e062a97337e3225385fa191 [new file with mode: 0644]

diff --git a/ca/677015fd9cf9e31e062a97337e3225385fa191 b/ca/677015fd9cf9e31e062a97337e3225385fa191
new file mode 100644 (file)
index 0000000..5397c92
--- /dev/null
@@ -0,0 +1,276 @@
+Return-Path: <chris@chris-wilson.co.uk>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id C4EAA431FC7\r
+       for <notmuch@notmuchmail.org>; Sat, 21 Nov 2009 16:44:40 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 7akSIXqxWQBF for <notmuch@notmuchmail.org>;\r
+       Sat, 21 Nov 2009 16:44:39 -0800 (PST)\r
+Received: from orsmga101.jf.intel.com (mga06.intel.com [134.134.136.21])\r
+       by olra.theworths.org (Postfix) with ESMTP id 0F4A9431FAE\r
+       for <notmuch@notmuchmail.org>; Sat, 21 Nov 2009 16:44:38 -0800 (PST)\r
+Received: from orsmga002.jf.intel.com ([10.7.209.21])\r
+       by orsmga101.jf.intel.com with ESMTP; 21 Nov 2009 16:44:30 -0800\r
+X-ExtLoop1: 1\r
+X-IronPort-AV: E=Sophos;i="4.47,265,1257148800"; d="scan'208";a="469444040"\r
+Received: from unknown (HELO localhost.localdomain) ([10.255.16.190])\r
+       by orsmga002.jf.intel.com with ESMTP; 21 Nov 2009 17:01:40 -0800\r
+From: Chris Wilson <chris@chris-wilson.co.uk>\r
+To: notmuch@notmuchmail.org\r
+Date: Sun, 22 Nov 2009 00:44:31 +0000\r
+Message-Id: <1258850672-28339-2-git-send-email-chris@chris-wilson.co.uk>\r
+X-Mailer: git-send-email 1.6.5.3\r
+In-Reply-To: <1258850672-28339-1-git-send-email-chris@chris-wilson.co.uk>\r
+References: <1258850672-28339-1-git-send-email-chris@chris-wilson.co.uk>\r
+Subject: [notmuch] [PATCH 1/2] notmuch-new: Only install SIGALRM if not\r
+       running under gdb\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.12\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 22 Nov 2009 00:44:41 -0000\r
+\r
+I felt sorry for Carl trying to step through an exception from xapian\r
+and suffering from the SIGALARMs..\r
+\r
+We can detect if the user launched notmuch under a debugger by either\r
+checking our cmdline for the presence of the gdb string or querying if\r
+valgrind is controlling our process. For the latter we need to add a\r
+compile time check for the valgrind development library, and so add the\r
+initial support to build Makefile.config from configure.\r
+\r
+Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>\r
+Reviewed-by: Carl Worth <cworth@cworth.org>\r
+[ickle: And do not install the timer when under the debugger]\r
+---\r
+ Makefile.config  |    1 +\r
+ Makefile.local   |    3 ++-\r
+ configure        |   21 +++++++++++++++++----\r
+ debugger.c       |   47 +++++++++++++++++++++++++++++++++++++++++++++++\r
+ notmuch-client.h |    3 +++\r
+ notmuch-new.c    |   49 ++++++++++++++++++++++++++++---------------------\r
+ 6 files changed, 98 insertions(+), 26 deletions(-)\r
+ create mode 100644 debugger.c\r
+\r
+diff --git a/Makefile.config b/Makefile.config\r
+index d72a39e..ddc7436 100644\r
+--- a/Makefile.config\r
++++ b/Makefile.config\r
+@@ -1,2 +1,3 @@\r
+ prefix = /usr/local\r
+ bash_completion_dir = /etc/bash_completion.d\r
++CFLAGS += -DHAVE_VALGRIND\r
+diff --git a/Makefile.local b/Makefile.local\r
+index 3c99624..efe76c8 100644\r
+--- a/Makefile.local\r
++++ b/Makefile.local\r
+@@ -3,6 +3,8 @@ all: notmuch notmuch.1.gz\r
+ emacs: notmuch.elc\r
\r
+ notmuch_client_srcs =         \\r
++      debugger.c              \\r
++      gmime-filter-reply.c    \\r
+       notmuch.c               \\r
+       notmuch-config.c        \\r
+       notmuch-dump.c          \\r
+@@ -14,7 +16,6 @@ notmuch_client_srcs =                \\r
+       notmuch-show.c          \\r
+       notmuch-tag.c           \\r
+       notmuch-time.c          \\r
+-      gmime-filter-reply.c    \\r
+       query-string.c          \\r
+       show-message.c\r
\r
+diff --git a/configure b/configure\r
+index fe46c8e..b4770ec 100755\r
+--- a/configure\r
++++ b/configure\r
+@@ -53,6 +53,14 @@ else\r
+     errors=$((errors + 1))\r
+ fi\r
\r
++if pkg-config --modversion valgrind > /dev/null 2>&1; then\r
++    echo "Checking for valgrind development files... Yes."\r
++    have_valgrind=-DHAVE_VALGRIND\r
++else\r
++    echo "Checking for valgrind development files... No."\r
++    have_valgrind=\r
++fi\r
++\r
+ if [ $errors -gt 0 ]; then\r
+     cat <<EOF\r
\r
+@@ -108,7 +116,8 @@ configure again to ensure the packages can be found, or simply run\r
\r
+ EOF\r
+     exit 1\r
+-else\r
++fi\r
++\r
+ cat <<EOF\r
\r
+ All required packages were found. You may now run the following\r
+@@ -118,6 +127,10 @@ commands to compile and install notmuch:\r
+       sudo make install\r
\r
+ EOF\r
+-    exit 0\r
+-fi\r
+-cat <<EOF\r
++\r
++# construct the Makefile.config\r
++cat > Makefile.config <<EOF\r
++prefix = /usr/local\r
++bash_completion_dir = /etc/bash_completion.d\r
++CFLAGS += ${have_valgrind}\r
++EOF\r
+diff --git a/debugger.c b/debugger.c\r
+new file mode 100644\r
+index 0000000..e8b9378\r
+--- /dev/null\r
++++ b/debugger.c\r
+@@ -0,0 +1,47 @@\r
++/* debugger.c - Some debugger utilities for the notmuch mail library\r
++ *\r
++ * Copyright © 2009 Chris Wilson\r
++ *\r
++ * This program is free software: you can redistribute it and/or modify\r
++ * it under the terms of the GNU General Public License as published by\r
++ * the Free Software Foundation, either version 3 of the License, or\r
++ * (at your option) any later version.\r
++ *\r
++ * This program is distributed in the hope that it will be useful,\r
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++ * GNU General Public License for more details.\r
++ *\r
++ * You should have received a copy of the GNU General Public License\r
++ * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
++ *\r
++ * Author: Chris Wilson <chris@chris-wilson.co.uk>\r
++ */\r
++\r
++#include "notmuch-client.h"\r
++\r
++#include <libgen.h>\r
++\r
++#if HAVE_VALGRIND\r
++#include <valgrind.h>\r
++#else\r
++#define RUNNING_ON_VALGRIND 0\r
++#endif\r
++\r
++notmuch_bool_t\r
++debugger_is_active (void)\r
++{\r
++    char buf[1024];\r
++\r
++    if (RUNNING_ON_VALGRIND)\r
++      return TRUE;\r
++\r
++    sprintf (buf, "/proc/%d/exe", getppid ());\r
++    if (readlink (buf, buf, sizeof (buf)) != -1 &&\r
++      strncmp (basename (buf), "gdb", 3) == 0)\r
++    {\r
++      return TRUE;\r
++    }\r
++\r
++    return FALSE;\r
++}\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index b65aa77..ea77686 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -179,4 +179,7 @@ notmuch_config_set_user_other_email (notmuch_config_t *config,\r
+                                    const char *other_email[],\r
+                                    size_t length);\r
\r
++notmuch_bool_t\r
++debugger_is_active (void);\r
++\r
+ #endif\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index 43cc4fb..1616ee9 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -259,6 +259,7 @@ add_files (notmuch_database_t *notmuch,\r
+     notmuch_status_t status;\r
+     struct sigaction action;\r
+     struct itimerval timerval;\r
++    notmuch_bool_t timer_is_active = FALSE;\r
\r
+     if (stat (path, &st)) {\r
+       fprintf (stderr, "Error reading directory %s: %s\n",\r
+@@ -272,31 +273,37 @@ add_files (notmuch_database_t *notmuch,\r
+     }\r
\r
+     /* Setup our handler for SIGALRM */\r
+-    memset (&action, 0, sizeof (struct sigaction));\r
+-    action.sa_handler = handle_sigalrm;\r
+-    sigemptyset (&action.sa_mask);\r
+-    action.sa_flags = SA_RESTART;\r
+-    sigaction (SIGALRM, &action, NULL);\r
+-\r
+-    /* Then start a timer to send SIGALRM once per second. */\r
+-    timerval.it_interval.tv_sec = 1;\r
+-    timerval.it_interval.tv_usec = 0;\r
+-    timerval.it_value.tv_sec = 1;\r
+-    timerval.it_value.tv_usec = 0;\r
+-    setitimer (ITIMER_REAL, &timerval, NULL);\r
++    if (! debugger_is_active ()) {\r
++      memset (&action, 0, sizeof (struct sigaction));\r
++      action.sa_handler = handle_sigalrm;\r
++      sigemptyset (&action.sa_mask);\r
++      action.sa_flags = SA_RESTART;\r
++      sigaction (SIGALRM, &action, NULL);\r
++\r
++      /* Then start a timer to send SIGALRM once per second. */\r
++      timerval.it_interval.tv_sec = 1;\r
++      timerval.it_interval.tv_usec = 0;\r
++      timerval.it_value.tv_sec = 1;\r
++      timerval.it_value.tv_usec = 0;\r
++      setitimer (ITIMER_REAL, &timerval, NULL);\r
++\r
++      timer_is_active = TRUE;\r
++    }\r
\r
+     status = add_files_recursive (notmuch, path, &st, state);\r
\r
+     /* Now stop the timer. */\r
+-    timerval.it_interval.tv_sec = 0;\r
+-    timerval.it_interval.tv_usec = 0;\r
+-    timerval.it_value.tv_sec = 0;\r
+-    timerval.it_value.tv_usec = 0;\r
+-    setitimer (ITIMER_REAL, &timerval, NULL);\r
+-\r
+-    /* And disable the signal handler. */\r
+-    action.sa_handler = SIG_IGN;\r
+-    sigaction (SIGALRM, &action, NULL);\r
++    if (timer_is_active) {\r
++      timerval.it_interval.tv_sec = 0;\r
++      timerval.it_interval.tv_usec = 0;\r
++      timerval.it_value.tv_sec = 0;\r
++      timerval.it_value.tv_usec = 0;\r
++      setitimer (ITIMER_REAL, &timerval, NULL);\r
++\r
++      /* And disable the signal handler. */\r
++      action.sa_handler = SIG_IGN;\r
++      sigaction (SIGALRM, &action, NULL);\r
++    }\r
\r
+     return status;\r
+ }\r
+-- \r
+1.6.5.3\r
+\r