1 Return-Path: <chris@chris-wilson.co.uk>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id C4EAA431FC7
\r
6 for <notmuch@notmuchmail.org>; Sat, 21 Nov 2009 16:44:40 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 Received: from olra.theworths.org ([127.0.0.1])
\r
9 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
10 with ESMTP id 7akSIXqxWQBF for <notmuch@notmuchmail.org>;
\r
11 Sat, 21 Nov 2009 16:44:39 -0800 (PST)
\r
12 Received: from orsmga101.jf.intel.com (mga06.intel.com [134.134.136.21])
\r
13 by olra.theworths.org (Postfix) with ESMTP id 0F4A9431FAE
\r
14 for <notmuch@notmuchmail.org>; Sat, 21 Nov 2009 16:44:38 -0800 (PST)
\r
15 Received: from orsmga002.jf.intel.com ([10.7.209.21])
\r
16 by orsmga101.jf.intel.com with ESMTP; 21 Nov 2009 16:44:30 -0800
\r
18 X-IronPort-AV: E=Sophos;i="4.47,265,1257148800"; d="scan'208";a="469444040"
\r
19 Received: from unknown (HELO localhost.localdomain) ([10.255.16.190])
\r
20 by orsmga002.jf.intel.com with ESMTP; 21 Nov 2009 17:01:40 -0800
\r
21 From: Chris Wilson <chris@chris-wilson.co.uk>
\r
22 To: notmuch@notmuchmail.org
\r
23 Date: Sun, 22 Nov 2009 00:44:31 +0000
\r
24 Message-Id: <1258850672-28339-2-git-send-email-chris@chris-wilson.co.uk>
\r
25 X-Mailer: git-send-email 1.6.5.3
\r
26 In-Reply-To: <1258850672-28339-1-git-send-email-chris@chris-wilson.co.uk>
\r
27 References: <1258850672-28339-1-git-send-email-chris@chris-wilson.co.uk>
\r
28 Subject: [notmuch] [PATCH 1/2] notmuch-new: Only install SIGALRM if not
\r
30 X-BeenThere: notmuch@notmuchmail.org
\r
31 X-Mailman-Version: 2.1.12
\r
33 List-Id: "Use and development of the notmuch mail system."
\r
34 <notmuch.notmuchmail.org>
\r
35 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
36 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
37 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
38 List-Post: <mailto:notmuch@notmuchmail.org>
\r
39 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
40 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
41 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
42 X-List-Received-Date: Sun, 22 Nov 2009 00:44:41 -0000
\r
44 I felt sorry for Carl trying to step through an exception from xapian
\r
45 and suffering from the SIGALARMs..
\r
47 We can detect if the user launched notmuch under a debugger by either
\r
48 checking our cmdline for the presence of the gdb string or querying if
\r
49 valgrind is controlling our process. For the latter we need to add a
\r
50 compile time check for the valgrind development library, and so add the
\r
51 initial support to build Makefile.config from configure.
\r
53 Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
\r
54 Reviewed-by: Carl Worth <cworth@cworth.org>
\r
55 [ickle: And do not install the timer when under the debugger]
\r
57 Makefile.config | 1 +
\r
58 Makefile.local | 3 ++-
\r
59 configure | 21 +++++++++++++++++----
\r
60 debugger.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
\r
61 notmuch-client.h | 3 +++
\r
62 notmuch-new.c | 49 ++++++++++++++++++++++++++++---------------------
\r
63 6 files changed, 98 insertions(+), 26 deletions(-)
\r
64 create mode 100644 debugger.c
\r
66 diff --git a/Makefile.config b/Makefile.config
\r
67 index d72a39e..ddc7436 100644
\r
68 --- a/Makefile.config
\r
69 +++ b/Makefile.config
\r
72 bash_completion_dir = /etc/bash_completion.d
\r
73 +CFLAGS += -DHAVE_VALGRIND
\r
74 diff --git a/Makefile.local b/Makefile.local
\r
75 index 3c99624..efe76c8 100644
\r
76 --- a/Makefile.local
\r
77 +++ b/Makefile.local
\r
78 @@ -3,6 +3,8 @@ all: notmuch notmuch.1.gz
\r
81 notmuch_client_srcs = \
\r
83 + gmime-filter-reply.c \
\r
87 @@ -14,7 +16,6 @@ notmuch_client_srcs = \
\r
91 - gmime-filter-reply.c \
\r
95 diff --git a/configure b/configure
\r
96 index fe46c8e..b4770ec 100755
\r
99 @@ -53,6 +53,14 @@ else
\r
100 errors=$((errors + 1))
\r
103 +if pkg-config --modversion valgrind > /dev/null 2>&1; then
\r
104 + echo "Checking for valgrind development files... Yes."
\r
105 + have_valgrind=-DHAVE_VALGRIND
\r
107 + echo "Checking for valgrind development files... No."
\r
111 if [ $errors -gt 0 ]; then
\r
114 @@ -108,7 +116,8 @@ configure again to ensure the packages can be found, or simply run
\r
123 All required packages were found. You may now run the following
\r
124 @@ -118,6 +127,10 @@ commands to compile and install notmuch:
\r
132 +# construct the Makefile.config
\r
133 +cat > Makefile.config <<EOF
\r
134 +prefix = /usr/local
\r
135 +bash_completion_dir = /etc/bash_completion.d
\r
136 +CFLAGS += ${have_valgrind}
\r
138 diff --git a/debugger.c b/debugger.c
\r
139 new file mode 100644
\r
140 index 0000000..e8b9378
\r
144 +/* debugger.c - Some debugger utilities for the notmuch mail library
\r
146 + * Copyright © 2009 Chris Wilson
\r
148 + * This program is free software: you can redistribute it and/or modify
\r
149 + * it under the terms of the GNU General Public License as published by
\r
150 + * the Free Software Foundation, either version 3 of the License, or
\r
151 + * (at your option) any later version.
\r
153 + * This program is distributed in the hope that it will be useful,
\r
154 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
155 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
156 + * GNU General Public License for more details.
\r
158 + * You should have received a copy of the GNU General Public License
\r
159 + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
161 + * Author: Chris Wilson <chris@chris-wilson.co.uk>
\r
164 +#include "notmuch-client.h"
\r
166 +#include <libgen.h>
\r
169 +#include <valgrind.h>
\r
171 +#define RUNNING_ON_VALGRIND 0
\r
175 +debugger_is_active (void)
\r
179 + if (RUNNING_ON_VALGRIND)
\r
182 + sprintf (buf, "/proc/%d/exe", getppid ());
\r
183 + if (readlink (buf, buf, sizeof (buf)) != -1 &&
\r
184 + strncmp (basename (buf), "gdb", 3) == 0)
\r
191 diff --git a/notmuch-client.h b/notmuch-client.h
\r
192 index b65aa77..ea77686 100644
\r
193 --- a/notmuch-client.h
\r
194 +++ b/notmuch-client.h
\r
195 @@ -179,4 +179,7 @@ notmuch_config_set_user_other_email (notmuch_config_t *config,
\r
196 const char *other_email[],
\r
200 +debugger_is_active (void);
\r
203 diff --git a/notmuch-new.c b/notmuch-new.c
\r
204 index 43cc4fb..1616ee9 100644
\r
205 --- a/notmuch-new.c
\r
206 +++ b/notmuch-new.c
\r
207 @@ -259,6 +259,7 @@ add_files (notmuch_database_t *notmuch,
\r
208 notmuch_status_t status;
\r
209 struct sigaction action;
\r
210 struct itimerval timerval;
\r
211 + notmuch_bool_t timer_is_active = FALSE;
\r
213 if (stat (path, &st)) {
\r
214 fprintf (stderr, "Error reading directory %s: %s\n",
\r
215 @@ -272,31 +273,37 @@ add_files (notmuch_database_t *notmuch,
\r
218 /* Setup our handler for SIGALRM */
\r
219 - memset (&action, 0, sizeof (struct sigaction));
\r
220 - action.sa_handler = handle_sigalrm;
\r
221 - sigemptyset (&action.sa_mask);
\r
222 - action.sa_flags = SA_RESTART;
\r
223 - sigaction (SIGALRM, &action, NULL);
\r
225 - /* Then start a timer to send SIGALRM once per second. */
\r
226 - timerval.it_interval.tv_sec = 1;
\r
227 - timerval.it_interval.tv_usec = 0;
\r
228 - timerval.it_value.tv_sec = 1;
\r
229 - timerval.it_value.tv_usec = 0;
\r
230 - setitimer (ITIMER_REAL, &timerval, NULL);
\r
231 + if (! debugger_is_active ()) {
\r
232 + memset (&action, 0, sizeof (struct sigaction));
\r
233 + action.sa_handler = handle_sigalrm;
\r
234 + sigemptyset (&action.sa_mask);
\r
235 + action.sa_flags = SA_RESTART;
\r
236 + sigaction (SIGALRM, &action, NULL);
\r
238 + /* Then start a timer to send SIGALRM once per second. */
\r
239 + timerval.it_interval.tv_sec = 1;
\r
240 + timerval.it_interval.tv_usec = 0;
\r
241 + timerval.it_value.tv_sec = 1;
\r
242 + timerval.it_value.tv_usec = 0;
\r
243 + setitimer (ITIMER_REAL, &timerval, NULL);
\r
245 + timer_is_active = TRUE;
\r
248 status = add_files_recursive (notmuch, path, &st, state);
\r
250 /* Now stop the timer. */
\r
251 - timerval.it_interval.tv_sec = 0;
\r
252 - timerval.it_interval.tv_usec = 0;
\r
253 - timerval.it_value.tv_sec = 0;
\r
254 - timerval.it_value.tv_usec = 0;
\r
255 - setitimer (ITIMER_REAL, &timerval, NULL);
\r
257 - /* And disable the signal handler. */
\r
258 - action.sa_handler = SIG_IGN;
\r
259 - sigaction (SIGALRM, &action, NULL);
\r
260 + if (timer_is_active) {
\r
261 + timerval.it_interval.tv_sec = 0;
\r
262 + timerval.it_interval.tv_usec = 0;
\r
263 + timerval.it_value.tv_sec = 0;
\r
264 + timerval.it_value.tv_usec = 0;
\r
265 + setitimer (ITIMER_REAL, &timerval, NULL);
\r
267 + /* And disable the signal handler. */
\r
268 + action.sa_handler = SIG_IGN;
\r
269 + sigaction (SIGALRM, &action, NULL);
\r