--- /dev/null
+Return-Path: <tomi.ollila@iki.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 04807431FAF\r
+ for <notmuch@notmuchmail.org>; Mon, 27 May 2013 23:34:23 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id wbuNETRABVh0 for <notmuch@notmuchmail.org>;\r
+ Mon, 27 May 2013 23:34:14 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by olra.theworths.org (Postfix) with ESMTP id A4DDF431FAE\r
+ for <notmuch@notmuchmail.org>; Mon, 27 May 2013 23:34:14 -0700 (PDT)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+ by guru.guru-group.fi (Postfix) with ESMTP id 13443100093;\r
+ Tue, 28 May 2013 09:34:09 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: Austin Clements <amdragon@MIT.EDU>\r
+Subject: Re: [PATCH v2 1/4] cli: add global option --stderr=FILE\r
+In-Reply-To: <20130527214436.GT5999@mit.edu>\r
+References: <1369557954-13439-1-git-send-email-tomi.ollila@iki.fi>\r
+ <1369557954-13439-2-git-send-email-tomi.ollila@iki.fi>\r
+ <20130527214436.GT5999@mit.edu>\r
+User-Agent: Notmuch/0.15.2+115~g12cf6af (http://notmuchmail.org) Emacs/24.3.1\r
+ (x86_64-unknown-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+ $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+ !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Tue, 28 May 2013 09:34:08 +0300\r
+Message-ID: <m2a9nfr4tb.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+Cc: notmuch@notmuchmail.org\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 28 May 2013 06:34:23 -0000\r
+\r
+On Tue, May 28 2013, Austin Clements <amdragon@MIT.EDU> wrote:\r
+\r
+> Quoth Tomi Ollila on May 26 at 11:45 am:\r
+>> With this option all writes to stderr are redirected to the spesified\r
+>> FILE (or to stdout on case FILE is '-'). This is immediately useful\r
+>> in emacs interface as some of its exec intefaces do not provide\r
+>> separation of stdout and stderr.\r
+>> ---\r
+>> notmuch-client.h | 1 +\r
+>> notmuch.c | 32 ++++++++++++++++++++++++++++++++\r
+>> 2 files changed, 33 insertions(+)\r
+>> \r
+>> diff --git a/notmuch-client.h b/notmuch-client.h\r
+>> index 45749a6..4a3c7ac 100644\r
+>> --- a/notmuch-client.h\r
+>> +++ b/notmuch-client.h\r
+>> @@ -54,6 +54,7 @@ typedef GMimeCipherContext notmuch_crypto_context_t;\r
+>> #include <sys/stat.h>\r
+>> #include <sys/time.h>\r
+>> #include <unistd.h>\r
+>> +#include <fcntl.h>\r
+>> #include <dirent.h>\r
+>> #include <errno.h>\r
+>> #include <signal.h>\r
+>> diff --git a/notmuch.c b/notmuch.c\r
+>> index f51a84f..654a568 100644\r
+>> --- a/notmuch.c\r
+>> +++ b/notmuch.c\r
+>> @@ -251,6 +251,32 @@ notmuch_command (notmuch_config_t *config,\r
+>> return 0;\r
+>> }\r
+>> \r
+>> +static int\r
+>> +redirect_stderr (const char * stderr_file)\r
+>> +{\r
+>> + if (strcmp (stderr_file, "-") == 0) {\r
+>> + if (dup2 (STDOUT_FILENO, STDERR_FILENO) < 0) {\r
+>> + perror ("dup2");\r
+>> + return 1;\r
+>> + }\r
+>> + } else {\r
+>> + int fd = open (stderr_file, O_WRONLY|O_CREAT|O_APPEND, 0644);\r
+>\r
+> I think this should include O_TRUNC; otherwise it's too error-prone to\r
+> use programmatically. \r
+\r
+You're right! I thought this one night and was supposed check that it is\r
+O_TRUNC there -- forgot and obviously it wasn't ;/\r
+\r
+> The permissions should be 0666 (if the user's\r
+> umask says things should be group or world writable, it's not our job\r
+> to disagree).\r
+\r
+I agree that 0644 is incorrect -- but IMHO it should be 0600 -- when the\r
+data is written to /tmp world-readable file gave others chance to read\r
+potentially sensitive information from that file...\r
+\r
+I'll ask this (also) in IRC -- if people generally agree the bits should\r
+be 0666 I'll do that change instead (even personally opposing ATM).\r
+\r
+I'll also do the man and NEWS chances suggested for v3.\r
+\r
+Thanks for the review (this also goes to Jani & Mark).\r
+\r
+Tomi\r
+\r
+>> + if (fd < 0) {\r
+>> + fprintf (stderr, "Error: Cannot redirect stderr to '%s': %s\n",\r
+>> + stderr_file, strerror (errno));\r
+>> + return 1;\r
+>> + }\r
+>> + if (fd != STDERR_FILENO) {\r
+>> + if (dup2 (fd, STDERR_FILENO) < 0) {\r
+>> + perror ("dup2");\r
+>> + return 1;\r
+>> + }\r
+>> + close (fd);\r
+>> + }\r
+>> + }\r
+>> + return 0;\r
+>> +}\r
+>> +\r
+>> int\r
+>> main (int argc, char *argv[])\r
+>> {\r
+>> @@ -259,6 +285,7 @@ main (int argc, char *argv[])\r
+>> const char *command_name = NULL;\r
+>> command_t *command;\r
+>> char *config_file_name = NULL;\r
+>> + char *stderr_file = NULL;\r
+>> notmuch_config_t *config;\r
+>> notmuch_bool_t print_help=FALSE, print_version=FALSE;\r
+>> int opt_index;\r
+>> @@ -268,6 +295,7 @@ main (int argc, char *argv[])\r
+>> { NOTMUCH_OPT_BOOLEAN, &print_help, "help", 'h', 0 },\r
+>> { NOTMUCH_OPT_BOOLEAN, &print_version, "version", 'v', 0 },\r
+>> { NOTMUCH_OPT_STRING, &config_file_name, "config", 'c', 0 },\r
+>> + { NOTMUCH_OPT_STRING, &stderr_file, "stderr", '\0', 0 },\r
+>> { 0, 0, 0, 0, 0 }\r
+>> };\r
+>> \r
+>> @@ -287,6 +315,10 @@ main (int argc, char *argv[])\r
+>> return 1;\r
+>> }\r
+>> \r
+>> + if (stderr_file && redirect_stderr (stderr_file) != 0) {\r
+>> + /* error already printed */\r
+>> + return 1;\r
+>> + }\r
+>> if (print_help)\r
+>> return notmuch_help_command (NULL, argc - 1, &argv[1]);\r
+>> \r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r