Re: [PATCH 1/2] Add Google Inc. to AUTHORS as a contributor.
[notmuch-archives.git] / c5 / 040fb4ecaeb3adec8613e7f54d769b7ed7431d
1 Return-Path: <bart@jukie.net>\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 4773D431FAE\r
6         for <notmuch@notmuchmail.org>; Fri, 27 Nov 2009 19:11:54 -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 6RGIAAiicpVn for <notmuch@notmuchmail.org>;\r
11         Fri, 27 Nov 2009 19:11:53 -0800 (PST)\r
12 Received: from tau.jukie.net (tau.jukie.net [216.239.93.128])\r
13         by olra.theworths.org (Postfix) with ESMTP id 4136D431FBC\r
14         for <notmuch@notmuchmail.org>; Fri, 27 Nov 2009 19:11:53 -0800 (PST)\r
15 Received: from localhost.localdomain (oxygen.jukie.net [10.10.10.8])\r
16         by tau.jukie.net (Postfix) with ESMTP id B1B37C008F5;\r
17         Fri, 27 Nov 2009 22:11:52 -0500 (EST)\r
18 From: Bart Trojanowski <bart@jukie.net>\r
19 To: notmuch@notmuchmail.org\r
20 Date: Fri, 27 Nov 2009 22:11:04 -0500\r
21 Message-Id: <1259377864-2523-1-git-send-email-bart@jukie.net>\r
22 X-Mailer: git-send-email 1.6.4.4.2.gc2f148\r
23 Cc: Bart Trojanowski <bart@jukie.net>\r
24 Subject: [notmuch] [PATCH RFC] debugger: detect presence of ptrace type\r
25         debuggers\r
26 X-BeenThere: notmuch@notmuchmail.org\r
27 X-Mailman-Version: 2.1.12\r
28 Precedence: list\r
29 List-Id: "Use and development of the notmuch mail system."\r
30         <notmuch.notmuchmail.org>\r
31 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
32         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
33 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
34 List-Post: <mailto:notmuch@notmuchmail.org>\r
35 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
36 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
37         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
38 X-List-Received-Date: Sat, 28 Nov 2009 03:11:54 -0000\r
39 \r
40 According to the internet [1], this is a more reliable way of detecting if\r
41 one is under the spell of a debugger.  Should work for ptrace, strace,\r
42 gdb, etc.  Basically anything that uses the ptrace() syscall.\r
43 \r
44 [1] http://vx.netlux.org/lib/vsc04.html\r
45 ---\r
46  debugger.c |    5 +++++\r
47  1 files changed, 5 insertions(+), 0 deletions(-)\r
48 \r
49 diff --git a/debugger.c b/debugger.c\r
50 index e8b9378..f486032 100644\r
51 --- a/debugger.c\r
52 +++ b/debugger.c\r
53 @@ -22,6 +22,8 @@\r
54  \r
55  #include <libgen.h>\r
56  \r
57 +#include <sys/ptrace.h>\r
58 +\r
59  #if HAVE_VALGRIND\r
60  #include <valgrind.h>\r
61  #else\r
62 @@ -36,6 +38,9 @@ debugger_is_active (void)\r
63      if (RUNNING_ON_VALGRIND)\r
64         return TRUE;\r
65  \r
66 +    if (ptrace(PTRACE_TRACEME, 0, 1, 0) < 0)\r
67 +       return TRUE;\r
68 +\r
69      sprintf (buf, "/proc/%d/exe", getppid ());\r
70      if (readlink (buf, buf, sizeof (buf)) != -1 &&\r
71         strncmp (basename (buf), "gdb", 3) == 0)\r
72 -- \r
73 1.6.4.4.2.gc2f148\r
74 \r