Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 4773D431FAE for ; Fri, 27 Nov 2009 19:11:54 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6RGIAAiicpVn for ; Fri, 27 Nov 2009 19:11:53 -0800 (PST) Received: from tau.jukie.net (tau.jukie.net [216.239.93.128]) by olra.theworths.org (Postfix) with ESMTP id 4136D431FBC for ; Fri, 27 Nov 2009 19:11:53 -0800 (PST) Received: from localhost.localdomain (oxygen.jukie.net [10.10.10.8]) by tau.jukie.net (Postfix) with ESMTP id B1B37C008F5; Fri, 27 Nov 2009 22:11:52 -0500 (EST) From: Bart Trojanowski To: notmuch@notmuchmail.org Date: Fri, 27 Nov 2009 22:11:04 -0500 Message-Id: <1259377864-2523-1-git-send-email-bart@jukie.net> X-Mailer: git-send-email 1.6.4.4.2.gc2f148 Cc: Bart Trojanowski Subject: [notmuch] [PATCH RFC] debugger: detect presence of ptrace type debuggers X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Nov 2009 03:11:54 -0000 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