1 Return-Path: <too@guru-group.fi>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id D1ED7431FDA
\r
6 for <notmuch@notmuchmail.org>; Thu, 23 May 2013 11:06:17 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id xJ5LVa+ZQT5L for <notmuch@notmuchmail.org>;
\r
16 Thu, 23 May 2013 11:06:11 -0700 (PDT)
\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 853B1431FAF
\r
19 for <notmuch@notmuchmail.org>; Thu, 23 May 2013 11:06:11 -0700 (PDT)
\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)
\r
21 id A77761002C4; Thu, 23 May 2013 21:06:07 +0300 (EEST)
\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
23 To: notmuch@notmuchmail.org
\r
24 Subject: [PATCH 1/4] cli: add global option --stderr=FILE
\r
25 Date: Thu, 23 May 2013 21:05:59 +0300
\r
26 Message-Id: <1369332362-4719-1-git-send-email-tomi.ollila@iki.fi>
\r
27 X-Mailer: git-send-email 1.8.0
\r
28 Cc: tomi.ollila@iki.fi
\r
29 X-BeenThere: notmuch@notmuchmail.org
\r
30 X-Mailman-Version: 2.1.13
\r
32 List-Id: "Use and development of the notmuch mail system."
\r
33 <notmuch.notmuchmail.org>
\r
34 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
35 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
36 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
37 List-Post: <mailto:notmuch@notmuchmail.org>
\r
38 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
39 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
40 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
41 X-List-Received-Date: Thu, 23 May 2013 18:06:18 -0000
\r
43 With this option all writes to stderr are redirected to the spesified
\r
44 FILE (or to stdout on case FILE is '-'). This is immediately useful
\r
45 in emacs interface as some of its exec intefaces do not provide
\r
46 separation of stdout and stderr.
\r
48 notmuch-client.h | 1 +
\r
49 notmuch.c | 31 +++++++++++++++++++++++++++++++
\r
50 2 files changed, 32 insertions(+)
\r
52 diff --git a/notmuch-client.h b/notmuch-client.h
\r
53 index 45749a6..4a3c7ac 100644
\r
54 --- a/notmuch-client.h
\r
55 +++ b/notmuch-client.h
\r
56 @@ -54,6 +54,7 @@ typedef GMimeCipherContext notmuch_crypto_context_t;
\r
57 #include <sys/stat.h>
\r
58 #include <sys/time.h>
\r
64 diff --git a/notmuch.c b/notmuch.c
\r
65 index f51a84f..77b5282 100644
\r
68 @@ -251,6 +251,31 @@ notmuch_command (notmuch_config_t *config,
\r
72 +static int redirect_stderr (const char * stderr_file)
\r
74 + if (strcmp (stderr_file, "-") == 0) {
\r
75 + if (dup2 (STDOUT_FILENO, STDERR_FILENO) < 0) {
\r
80 + int fd = open (stderr_file, O_WRONLY|O_CREAT|O_APPEND, 0644);
\r
82 + fprintf (stderr, "Error: Cannot redirect stderr to '%s': %s\n",
\r
83 + stderr_file, strerror (errno));
\r
86 + if (fd != STDERR_FILENO) {
\r
87 + if (dup2 (fd, STDERR_FILENO) < 0) {
\r
98 main (int argc, char *argv[])
\r
100 @@ -259,6 +284,7 @@ main (int argc, char *argv[])
\r
101 const char *command_name = NULL;
\r
102 command_t *command;
\r
103 char *config_file_name = NULL;
\r
104 + char *stderr_file = NULL;
\r
105 notmuch_config_t *config;
\r
106 notmuch_bool_t print_help=FALSE, print_version=FALSE;
\r
108 @@ -268,6 +294,7 @@ main (int argc, char *argv[])
\r
109 { NOTMUCH_OPT_BOOLEAN, &print_help, "help", 'h', 0 },
\r
110 { NOTMUCH_OPT_BOOLEAN, &print_version, "version", 'v', 0 },
\r
111 { NOTMUCH_OPT_STRING, &config_file_name, "config", 'c', 0 },
\r
112 + { NOTMUCH_OPT_STRING, &stderr_file, "stderr", '\0', 0 },
\r
116 @@ -287,6 +314,10 @@ main (int argc, char *argv[])
\r
120 + if (stderr_file && redirect_stderr (stderr_file) != 0) {
\r
121 + /* error already printed */
\r
125 return notmuch_help_command (NULL, argc - 1, &argv[1]);
\r