From 91d2c5c265d43c24e3a5b79ba5d19eb12bc1492d Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Sat, 24 Nov 2012 13:24:33 +0000 Subject: [PATCH] Re: [PATCH v2 1/7] cli: allow query to come from stdin --- a6/563b1f33b881b806dd4619dd6ac17e0a36bf0a | 159 ++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 a6/563b1f33b881b806dd4619dd6ac17e0a36bf0a diff --git a/a6/563b1f33b881b806dd4619dd6ac17e0a36bf0a b/a6/563b1f33b881b806dd4619dd6ac17e0a36bf0a new file mode 100644 index 000000000..9099c558a --- /dev/null +++ b/a6/563b1f33b881b806dd4619dd6ac17e0a36bf0a @@ -0,0 +1,159 @@ +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 0DD9D431FAF + for ; Sat, 24 Nov 2012 05:24:41 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 1.401 +X-Spam-Level: * +X-Spam-Status: No, score=1.401 tagged_above=-999 required=5 + tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, + FREEMAIL_REPLY=2.499, NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] + 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 nj46y3h3PQo2 for ; + Sat, 24 Nov 2012 05:24:40 -0800 (PST) +Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 31EC5431FAE + for ; Sat, 24 Nov 2012 05:24:40 -0800 (PST) +Received: from smtp.qmul.ac.uk ([138.37.6.40]) + by mail2.qmul.ac.uk with esmtp (Exim 4.71) + (envelope-from ) + id 1TcFii-0001xt-U8; Sat, 24 Nov 2012 13:24:35 +0000 +Received: from 93-97-24-31.zone5.bethere.co.uk ([93.97.24.31] helo=localhost) + by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) + (envelope-from ) + id 1TcFii-0007Ms-JS; Sat, 24 Nov 2012 13:24:32 +0000 +From: Mark Walters +To: notmuch@notmuchmail.org +Subject: Re: [PATCH v2 1/7] cli: allow query to come from stdin +In-Reply-To: <1353763256-32336-2-git-send-email-markwalters1009@gmail.com> +References: <1353763256-32336-1-git-send-email-markwalters1009@gmail.com> + <1353763256-32336-2-git-send-email-markwalters1009@gmail.com> +User-Agent: Notmuch/0.14+81~g9730584 (http://notmuchmail.org) Emacs/23.4.1 + (x86_64-pc-linux-gnu) +Date: Sat, 24 Nov 2012 13:24:33 +0000 +Message-ID: <87mwy7jfqm.fsf@qmul.ac.uk> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Sender-Host-Address: 93.97.24.31 +X-QM-SPAM-Info: Sender has good ham record. :) +X-QM-Body-MD5: 9fbe8b4722f780f6d807d328c7aee5c2 (of first 20000 bytes) +X-SpamAssassin-Score: -1.2 +X-SpamAssassin-SpamBar: - +X-SpamAssassin-Report: The QM spam filters have analysed this message to + determine if it is + spam. We require at least 5.0 points to mark a message as spam. + This message scored -1.2 points. + Summary of the scoring: + * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, + * medium trust + * [138.37.6.40 listed in list.dnswl.org] + * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail + provider * (markwalters1009[at]gmail.com) + * 1.0 FREEMAIL_REPLY From and body contain different freemails + * 0.1 AWL AWL: From: address is in the auto white-list +X-QM-Scan-Virus: ClamAV says the message is clean +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, 24 Nov 2012 13:24:41 -0000 + + +I should have said the code for reading from stdin was +stolen from Peter's patch for notmuch-insert +id:1343223767-9812-4-git-send-email-novalazy@gmail.com +(errors are of course mine) + +My apologies for not mentioning this in the commit message. + +Mark + + + +On Sat, 24 Nov 2012, markwalters1009 wrote: +> From: Mark Walters +> +> After this series there will be times when a caller will want to pass +> a very large query string to notmuch (eg a list of 10,000 message-ids) +> and this can exceed the size of ARG_MAX. Hence allow notmuch to take +> the query from stdin (if the query is -). +> --- +> query-string.c | 41 +++++++++++++++++++++++++++++++++++++++++ +> 1 files changed, 41 insertions(+), 0 deletions(-) +> +> diff --git a/query-string.c b/query-string.c +> index 6536512..b1fbdeb 100644 +> --- a/query-string.c +> +++ b/query-string.c +> @@ -20,6 +20,44 @@ +> +> #include "notmuch-client.h" +> +> +/* Read a single query string from STDIN, using +> + * 'ctx' as the talloc owner for all allocations. +> + * +> + * This function returns NULL in case of insufficient memory or read +> + * errors. +> + */ +> +static char * +> +query_string_from_stdin (void *ctx) +> +{ +> + char *query_string; +> + char buf[4096]; +> + ssize_t remain; +> + +> + query_string = talloc_strdup (ctx, ""); +> + if (query_string == NULL) +> + return NULL; +> + +> + for (;;) { +> + remain = read (STDIN_FILENO, buf, sizeof(buf) - 1); +> + if (remain == 0) +> + break; +> + if (remain < 0) { +> + if (errno == EINTR) +> + continue; +> + fprintf (stderr, "Error: reading from standard input: %s\n", +> + strerror (errno)); +> + return NULL; +> + } +> + +> + buf[remain] = '\0'; +> + query_string = talloc_strdup_append (query_string, buf); +> + if (query_string == NULL) +> + return NULL; +> + } +> + +> + return query_string; +> +} +> + +> /* Construct a single query string from the passed arguments, using +> * 'ctx' as the talloc owner for all allocations. +> * +> @@ -35,6 +73,9 @@ query_string_from_args (void *ctx, int argc, char *argv[]) +> char *query_string; +> int i; +> +> + if ((argc == 1) && (strcmp ("-", argv[0]) == 0)) +> + return query_string_from_stdin (ctx); +> + +> query_string = talloc_strdup (ctx, ""); +> if (query_string == NULL) +> return NULL; +> -- +> 1.7.9.1 -- 2.26.2