From d463de69e7819ed13ae67d744ba85343a86a424c Mon Sep 17 00:00:00 2001 From: Tomi Ollila Date: Sun, 25 Nov 2012 00:34:19 +0200 Subject: [PATCH] Re: [PATCH v2 1/7] cli: allow query to come from stdin --- df/42a3d5999a2d7f00e8e30764a96cb4d8426031 | 137 ++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 df/42a3d5999a2d7f00e8e30764a96cb4d8426031 diff --git a/df/42a3d5999a2d7f00e8e30764a96cb4d8426031 b/df/42a3d5999a2d7f00e8e30764a96cb4d8426031 new file mode 100644 index 000000000..be45fc866 --- /dev/null +++ b/df/42a3d5999a2d7f00e8e30764a96cb4d8426031 @@ -0,0 +1,137 @@ +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 5186D431FAF + for ; Sat, 24 Nov 2012 14:34:21 -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 rnQ+3MEYycJ8 for ; + Sat, 24 Nov 2012 14:34:21 -0800 (PST) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by olra.theworths.org (Postfix) with ESMTP id CD668431FAE + for ; Sat, 24 Nov 2012 14:34:20 -0800 (PST) +Received: from guru.guru-group.fi (localhost [IPv6:::1]) + by guru.guru-group.fi (Postfix) with ESMTP id 44C7F10010B; + Sun, 25 Nov 2012 00:34:19 +0200 (EET) +From: Tomi Ollila +To: markwalters1009 , 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+84~g8a199bf (http://notmuchmail.org) Emacs/24.2.1 + (x86_64-unknown-linux-gnu) +X-Face: HhBM'cA~ +MIME-Version: 1.0 +Content-Type: text/plain +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 22:34:21 -0000 + +On Sat, Nov 24 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) + +Austin provided pretty nice alternative implementation of +query_string_from_stdin() in his reply so I decline to +comment minor formatting issue below :D + +> +{ +> + 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)) + +the argument order in strcmp() is not consistent with all the +other uses of strcmp () in the codebase. + +> + return query_string_from_stdin (ctx); +> + +> query_string = talloc_strdup (ctx, ""); +> if (query_string == NULL) +> return NULL; +> -- +> 1.7.9.1 + +Tomi -- 2.26.2