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 421AC431FCF for ; Sat, 19 Jan 2013 10:26:43 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled 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 9GP82TeDpERI for ; Sat, 19 Jan 2013 10:26:42 -0800 (PST) Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id C0377431FD0 for ; Sat, 19 Jan 2013 10:26:11 -0800 (PST) Received: from fctnnbsc30w-156034082078.dhcp-dynamic.fibreop.nb.bellaliant.net ([156.34.82.78] helo=zancas.localnet) by tesseract.cs.unb.ca with esmtpsa (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1Twd7J-0007xL-7c; Sat, 19 Jan 2013 14:26:09 -0400 Received: from bremner by zancas.localnet with local (Exim 4.80) (envelope-from ) id 1Twd7D-0005au-L9; Sat, 19 Jan 2013 14:26:03 -0400 From: david@tethera.net To: notmuch@notmuchmail.org Subject: [PATCH 5/7] CLI: add --leak-report top level option Date: Sat, 19 Jan 2013 14:25:56 -0400 Message-Id: <1358619958-21209-6-git-send-email-david@tethera.net> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1358619958-21209-1-git-send-email-david@tethera.net> References: <1358619958-21209-1-git-send-email-david@tethera.net> X-Spam_bar: - Cc: David Bremner X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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, 19 Jan 2013 18:26:43 -0000 From: David Bremner This roughly mimics the samba4 argument. The presence of the command line argument overrides any value of NOTMUCH_TALLOC_REPORT in the environment. --- man/man1/notmuch.1 | 8 ++++++++ notmuch.c | 18 +++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/man/man1/notmuch.1 b/man/man1/notmuch.1 index 6bf9b2e..5c58c41 100644 --- a/man/man1/notmuch.1 +++ b/man/man1/notmuch.1 @@ -70,6 +70,14 @@ Print a synopsis of available commands and exit. Print the installed version of notmuch, and exit. .RE +.RS 4 +.TP 4 +.BI \-\-leak-report= path + +Write a detailed report of all memory allocated via talloc to +.I path +.RE + .SH COMMANDS diff --git a/notmuch.c b/notmuch.c index a674481..f8d4b35 100644 --- a/notmuch.c +++ b/notmuch.c @@ -250,11 +250,13 @@ main (int argc, char *argv[]) command_t *command; unsigned int i; notmuch_bool_t print_help=FALSE, print_version=FALSE; + const char* leak_report=NULL; int opt_index; notmuch_opt_desc_t options[] = { { NOTMUCH_OPT_BOOLEAN, &print_help, "help", 'h', 0 }, { NOTMUCH_OPT_BOOLEAN, &print_version, "version", 'v', 0 }, + { NOTMUCH_OPT_STRING, &leak_report, "leak-report", 'l', 0 }, { 0, 0, 0, 0, 0 } }; @@ -290,21 +292,15 @@ main (int argc, char *argv[]) if (strcmp (argv[opt_index], command->name) == 0) { int ret; - char *talloc_report; ret = (command->function)(local, argc - opt_index, argv + opt_index); - /* in the future support for this environment variable may - * be supplemented or replaced by command line arguments - * --leak-report and/or --leak-report-full */ - - talloc_report = getenv ("NOTMUCH_TALLOC_REPORT"); - - /* this relies on the previous call to - * talloc_enable_null_tracking */ + if (leak_report == NULL) { + leak_report = getenv ("NOTMUCH_TALLOC_REPORT"); + } - if (talloc_report && strcmp (talloc_report, "") != 0) { - FILE *report = fopen (talloc_report, "w"); + if (leak_report && (strcmp (leak_report, "") != 0)) { + FILE *report = fopen (leak_report, "w"); talloc_report_full (NULL, report); } -- 1.7.10.4