* Avoid installing SIGALRMs when under the debugger.
@ 2009-11-22 0:44 Chris Wilson
2009-11-22 0:44 ` [PATCH 1/2] notmuch-new: Only install SIGALRM if not running under gdb Chris Wilson
2009-11-22 0:44 ` [PATCH 2/2] notmuch-new: Only print the regular progress report when on a tty Chris Wilson
0 siblings, 2 replies; 4+ messages in thread
From: Chris Wilson @ 2009-11-22 0:44 UTC (permalink / raw)
To: notmuch
Gah, I'm tired and using "git send-email HEAD^" is too easy. Here is the
most recent pair of patches in possibly a working state.
-ickle
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] notmuch-new: Only install SIGALRM if not running under gdb
2009-11-22 0:44 Avoid installing SIGALRMs when under the debugger Chris Wilson
@ 2009-11-22 0:44 ` Chris Wilson
2009-11-22 4:38 ` Carl Worth
2009-11-22 0:44 ` [PATCH 2/2] notmuch-new: Only print the regular progress report when on a tty Chris Wilson
1 sibling, 1 reply; 4+ messages in thread
From: Chris Wilson @ 2009-11-22 0:44 UTC (permalink / raw)
To: notmuch
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 6597 bytes --]
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 <chris@chris-wilson.co.uk>
Reviewed-by: Carl Worth <cworth@cworth.org>
[ickle: And do not install the timer when under the debugger]
---
Makefile.config | 1 +
Makefile.local | 3 ++-
configure | 21 +++++++++++++++++----
debugger.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
notmuch-client.h | 3 +++
notmuch-new.c | 49 ++++++++++++++++++++++++++++---------------------
6 files changed, 98 insertions(+), 26 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 <<EOF
@@ -108,7 +116,8 @@ configure again to ensure the packages can be found, or simply run
EOF
exit 1
-else
+fi
+
cat <<EOF
All required packages were found. You may now run the following
@@ -118,6 +127,10 @@ commands to compile and install notmuch:
sudo make install
EOF
- exit 0
-fi
-cat <<EOF
+
+# construct the Makefile.config
+cat > Makefile.config <<EOF
+prefix = /usr/local
+bash_completion_dir = /etc/bash_completion.d
+CFLAGS += ${have_valgrind}
+EOF
diff --git a/debugger.c b/debugger.c
new file mode 100644
index 0000000..e8b9378
--- /dev/null
+++ b/debugger.c
@@ -0,0 +1,47 @@
+/* debugger.c - Some debugger utilities for the notmuch mail library
+ *
+ * Copyright © 2009 Chris Wilson
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://www.gnu.org/licenses/ .
+ *
+ * Author: Chris Wilson <chris@chris-wilson.co.uk>
+ */
+
+#include "notmuch-client.h"
+
+#include <libgen.h>
+
+#if HAVE_VALGRIND
+#include <valgrind.h>
+#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..1616ee9 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -259,6 +259,7 @@ add_files (notmuch_database_t *notmuch,
notmuch_status_t status;
struct sigaction action;
struct itimerval timerval;
+ notmuch_bool_t timer_is_active = FALSE;
if (stat (path, &st)) {
fprintf (stderr, "Error reading directory %s: %s\n",
@@ -272,31 +273,37 @@ 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);
-
- /* Then start a timer to send SIGALRM once per second. */
- timerval.it_interval.tv_sec = 1;
- timerval.it_interval.tv_usec = 0;
- timerval.it_value.tv_sec = 1;
- timerval.it_value.tv_usec = 0;
- setitimer (ITIMER_REAL, &timerval, 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;
+ timerval.it_interval.tv_usec = 0;
+ timerval.it_value.tv_sec = 1;
+ timerval.it_value.tv_usec = 0;
+ setitimer (ITIMER_REAL, &timerval, NULL);
+
+ timer_is_active = TRUE;
+ }
status = add_files_recursive (notmuch, path, &st, state);
/* Now stop the timer. */
- timerval.it_interval.tv_sec = 0;
- timerval.it_interval.tv_usec = 0;
- timerval.it_value.tv_sec = 0;
- timerval.it_value.tv_usec = 0;
- setitimer (ITIMER_REAL, &timerval, NULL);
-
- /* And disable the signal handler. */
- action.sa_handler = SIG_IGN;
- sigaction (SIGALRM, &action, NULL);
+ if (timer_is_active) {
+ timerval.it_interval.tv_sec = 0;
+ timerval.it_interval.tv_usec = 0;
+ timerval.it_value.tv_sec = 0;
+ timerval.it_value.tv_usec = 0;
+ setitimer (ITIMER_REAL, &timerval, NULL);
+
+ /* And disable the signal handler. */
+ action.sa_handler = SIG_IGN;
+ sigaction (SIGALRM, &action, NULL);
+ }
return status;
}
--
1.6.5.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] notmuch-new: Only print the regular progress report when on a tty
2009-11-22 0:44 Avoid installing SIGALRMs when under the debugger Chris Wilson
2009-11-22 0:44 ` [PATCH 1/2] notmuch-new: Only install SIGALRM if not running under gdb Chris Wilson
@ 2009-11-22 0:44 ` Chris Wilson
1 sibling, 0 replies; 4+ messages in thread
From: Chris Wilson @ 2009-11-22 0:44 UTC (permalink / raw)
To: notmuch
Check that the stdout is connected to an interactive terminal with
isatty() before installing the periodic timer to print progress reports.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
notmuch-new.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/notmuch-new.c b/notmuch-new.c
index 1616ee9..0dd2784 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -20,6 +20,8 @@
#include "notmuch-client.h"
+#include <unistd.h>
+
static volatile sig_atomic_t do_add_files_print_progress = 0;
static void
@@ -273,7 +275,7 @@ add_files (notmuch_database_t *notmuch,
}
/* Setup our handler for SIGALRM */
- if (! debugger_is_active ()) {
+ if (isatty (fileno (stdout)) && ! debugger_is_active ()) {
memset (&action, 0, sizeof (struct sigaction));
action.sa_handler = handle_sigalrm;
sigemptyset (&action.sa_mask);
--
1.6.5.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] notmuch-new: Only install SIGALRM if not running under gdb
2009-11-22 0:44 ` [PATCH 1/2] notmuch-new: Only install SIGALRM if not running under gdb Chris Wilson
@ 2009-11-22 4:38 ` Carl Worth
0 siblings, 0 replies; 4+ messages in thread
From: Carl Worth @ 2009-11-22 4:38 UTC (permalink / raw)
To: Chris Wilson, notmuch
On Sun, 22 Nov 2009 00:44:31 +0000, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> I felt sorry for Carl trying to step through an exception from xapian
> and suffering from the SIGALARMs..
You're too kind, Chris. These are both pushed.
And did you notice the way I didn't push as soon as I found your patches
in my inbox, but this time I looked for the *next* set of patches. ;-)
-Carl
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-11-22 4:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-22 0:44 Avoid installing SIGALRMs when under the debugger Chris Wilson
2009-11-22 0:44 ` [PATCH 1/2] notmuch-new: Only install SIGALRM if not running under gdb Chris Wilson
2009-11-22 4:38 ` Carl Worth
2009-11-22 0:44 ` [PATCH 2/2] notmuch-new: Only print the regular progress report when on a tty Chris Wilson
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.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).