[notmuch] [PATCH RFC] debugger: detect presence of ptrace type debuggers

2009-11-27 Thread Carl Worth
On Fri, 27 Nov 2009 22:11:04 -0500, Bart Trojanowski  wrote:
> According to the internet [1], this is a more reliable way of detecting if
> one is under the spell of a debugger.  Should work for ptrace, strace,
> gdb, etc.  Basically anything that uses the ptrace() syscall.

Doesn't avoid having side effects in the non-debugger case:

$ ./notmuch new
No new mail---and that's not much.

[1]+  Stopped ./notmuch new
$

Not pushed.

-Carl
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 



[notmuch] [PATCH RFC] debugger: detect presence of ptrace type debuggers

2009-11-27 Thread Bart Trojanowski
According to the internet [1], this is a more reliable way of detecting if
one is under the spell of a debugger.  Should work for ptrace, strace,
gdb, etc.  Basically anything that uses the ptrace() syscall.

[1] http://vx.netlux.org/lib/vsc04.html
---
 debugger.c |5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/debugger.c b/debugger.c
index e8b9378..f486032 100644
--- a/debugger.c
+++ b/debugger.c
@@ -22,6 +22,8 @@

 #include 

+#include 
+
 #if HAVE_VALGRIND
 #include 
 #else
@@ -36,6 +38,9 @@ debugger_is_active (void)
 if (RUNNING_ON_VALGRIND)
return TRUE;

+if (ptrace(PTRACE_TRACEME, 0, 1, 0) < 0)
+   return TRUE;
+
 sprintf (buf, "/proc/%d/exe", getppid ());
 if (readlink (buf, buf, sizeof (buf)) != -1 &&
strncmp (basename (buf), "gdb", 3) == 0)
-- 
1.6.4.4.2.gc2f148