unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Bart Trojanowski <bart@jukie.net>
To: notmuch@notmuchmail.org
Cc: Bart Trojanowski <bart@jukie.net>
Subject: [PATCH RFC] debugger: detect presence of ptrace type debuggers
Date: Fri, 27 Nov 2009 22:11:04 -0500	[thread overview]
Message-ID: <1259377864-2523-1-git-send-email-bart@jukie.net> (raw)

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 <libgen.h>
 
+#include <sys/ptrace.h>
+
 #if HAVE_VALGRIND
 #include <valgrind.h>
 #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

             reply	other threads:[~2009-11-28  3:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-28  3:11 Bart Trojanowski [this message]
2009-11-28  6:17 ` [PATCH RFC] debugger: detect presence of ptrace type debuggers Carl Worth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1259377864-2523-1-git-send-email-bart@jukie.net \
    --to=bart@jukie.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).