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 2DB36431FAF for ; Sat, 25 May 2013 02:05:01 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.098 X-Spam-Level: X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5 tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, 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 KG9kmXEfnmbt for ; Sat, 25 May 2013 02:04:53 -0700 (PDT) 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 DC817431FAE for ; Sat, 25 May 2013 02:04:52 -0700 (PDT) Received: from smtp.qmul.ac.uk ([138.37.6.40]) by mail2.qmul.ac.uk with esmtp (Exim 4.71) (envelope-from ) id 1UgAP4-0002Hr-K2; Sat, 25 May 2013 10:04:49 +0100 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.71) (envelope-from ) id 1UgAP4-00047M-BG; Sat, 25 May 2013 10:04:42 +0100 From: Mark Walters To: Tomi Ollila , notmuch@notmuchmail.org Subject: Re: [PATCH 1/4] cli: add global option --stderr=FILE In-Reply-To: <1369332362-4719-1-git-send-email-tomi.ollila@iki.fi> References: <1369332362-4719-1-git-send-email-tomi.ollila@iki.fi> User-Agent: Notmuch/0.14+255~gff3cc55 (http://notmuchmail.org) Emacs/23.4.1 (x86_64-pc-linux-gnu) Date: Sat, 25 May 2013 10:04:41 +0100 Message-ID: <8738tbph06.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: 3427afa8f305b766055ca239a5bcb0fa (of first 20000 bytes) X-SpamAssassin-Score: -0.1 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 -0.1 points. Summary of the scoring: * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider * (markwalters1009[at]gmail.com) * -0.1 AWL AWL: From: address is in the auto white-list X-QM-Scan-Virus: ClamAV says the message is clean Cc: tomi.ollila@iki.fi 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, 25 May 2013 09:05:01 -0000 This series looks good to me and it does simplify the emacs async error handling very usefully. +1 Best wishes Mark On Thu, 23 May 2013, Tomi Ollila wrote: > With this option all writes to stderr are redirected to the spesified > FILE (or to stdout on case FILE is '-'). This is immediately useful > in emacs interface as some of its exec intefaces do not provide > separation of stdout and stderr. > --- > notmuch-client.h | 1 + > notmuch.c | 31 +++++++++++++++++++++++++++++++ > 2 files changed, 32 insertions(+) > > diff --git a/notmuch-client.h b/notmuch-client.h > index 45749a6..4a3c7ac 100644 > --- a/notmuch-client.h > +++ b/notmuch-client.h > @@ -54,6 +54,7 @@ typedef GMimeCipherContext notmuch_crypto_context_t; > #include > #include > #include > +#include > #include > #include > #include > diff --git a/notmuch.c b/notmuch.c > index f51a84f..77b5282 100644 > --- a/notmuch.c > +++ b/notmuch.c > @@ -251,6 +251,31 @@ notmuch_command (notmuch_config_t *config, > return 0; > } > > +static int redirect_stderr (const char * stderr_file) > +{ > + if (strcmp (stderr_file, "-") == 0) { > + if (dup2 (STDOUT_FILENO, STDERR_FILENO) < 0) { > + perror ("dup2"); > + return 1; > + } > + } else { > + int fd = open (stderr_file, O_WRONLY|O_CREAT|O_APPEND, 0644); > + if (fd < 0) { > + fprintf (stderr, "Error: Cannot redirect stderr to '%s': %s\n", > + stderr_file, strerror (errno)); > + return 1; > + } > + if (fd != STDERR_FILENO) { > + if (dup2 (fd, STDERR_FILENO) < 0) { > + perror ("dup2"); > + return 1; > + } > + close (fd); > + } > + } > + return 0; > +} > + > int > main (int argc, char *argv[]) > { > @@ -259,6 +284,7 @@ main (int argc, char *argv[]) > const char *command_name = NULL; > command_t *command; > char *config_file_name = NULL; > + char *stderr_file = NULL; > notmuch_config_t *config; > notmuch_bool_t print_help=FALSE, print_version=FALSE; > int opt_index; > @@ -268,6 +294,7 @@ main (int argc, char *argv[]) > { NOTMUCH_OPT_BOOLEAN, &print_help, "help", 'h', 0 }, > { NOTMUCH_OPT_BOOLEAN, &print_version, "version", 'v', 0 }, > { NOTMUCH_OPT_STRING, &config_file_name, "config", 'c', 0 }, > + { NOTMUCH_OPT_STRING, &stderr_file, "stderr", '\0', 0 }, > { 0, 0, 0, 0, 0 } > }; > > @@ -287,6 +314,10 @@ main (int argc, char *argv[]) > return 1; > } > > + if (stderr_file && redirect_stderr (stderr_file) != 0) { > + /* error already printed */ > + return 1; > + } > if (print_help) > return notmuch_help_command (NULL, argc - 1, &argv[1]); > > -- > 1.8.1.4 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch