[PATCH] cli: Flush stdout before fork()ing to run hooks
authorAustin Clements <amdragon@MIT.EDU>
Sun, 23 Mar 2014 21:22:26 +0000 (17:22 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:00:57 +0000 (10:00 -0800)
5b/bd7452772cd67fda54330adb07f3657682e25a [new file with mode: 0644]

diff --git a/5b/bd7452772cd67fda54330adb07f3657682e25a b/5b/bd7452772cd67fda54330adb07f3657682e25a
new file mode 100644 (file)
index 0000000..fe11dd1
--- /dev/null
@@ -0,0 +1,101 @@
+Return-Path: <amdragon@mit.edu>\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 4CF70431FBD\r
+       for <notmuch@notmuchmail.org>; Sun, 23 Mar 2014 14:22:42 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 D-lP+0xdV0kc for <notmuch@notmuchmail.org>;\r
+       Sun, 23 Mar 2014 14:22:36 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-1.mit.edu (dmz-mailsec-scanner-1.mit.edu\r
+       [18.9.25.12])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id DA89F431FB6\r
+       for <notmuch@notmuchmail.org>; Sun, 23 Mar 2014 14:22:35 -0700 (PDT)\r
+X-AuditID: 1209190c-f794a6d000000c27-68-532f509a83e8\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+       (using TLS with cipher AES256-SHA (256/256 bits))\r
+       (Client did not present a certificate)\r
+       by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 19.8E.03111.A905F235; Sun, 23 Mar 2014 17:22:34 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+       by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id s2NLMWxo019930; \r
+       Sun, 23 Mar 2014 17:22:33 -0400\r
+Received: from drake.dyndns.org\r
+       (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+       [216.15.114.40]) (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s2NLMV4e016139\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Sun, 23 Mar 2014 17:22:32 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1WRpqh-0006yu-2S; Sun, 23 Mar 2014 17:22:31 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] cli: Flush stdout before fork()ing to run hooks\r
+Date: Sun, 23 Mar 2014 17:22:26 -0400\r
+Message-Id: <1395609746-26801-1-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.8.4.rc3\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFprNIsWRmVeSWpSXmKPExsUixG6nrjsrQD/Y4O1KI4vrN2cyOzB6PFt1\r
+       izmAMYrLJiU1J7MstUjfLoErY8m5pWwFf1krZlw/z9bAeIKli5GTQ0LARKLtwlwoW0ziwr31\r
+       bF2MXBxCArOZJH40TWaEcDYySrze9Y0dwrnDJHHi4ApWCGcuo0TTn2XMIP1sAhoS2/YvZwSx\r
+       RQSkJXbenQ1UxMHBLKAm8adLBSQsLOAgcXvrS7ByFgFViYa/E9lBbF6g+MS2k2wQZyhJLDy1\r
+       jXUCI+8CRoZVjLIpuVW6uYmZOcWpybrFyYl5ealFuoZ6uZkleqkppZsYQWHAKcmzg/HNQaVD\r
+       jAIcjEo8vC+t9IOFWBPLiitzDzFKcjApifL+dgcK8SXlp1RmJBZnxBeV5qQWH2KU4GBWEuGN\r
+       dAXK8aYkVlalFuXDpKQ5WJTEeeU5tIOFBNITS1KzU1MLUotgsjIcHEoSvOf9gRoFi1LTUyvS\r
+       MnNKENJMHJwgw3mAhu8EqeEtLkjMLc5Mh8ifYlSUEuf9CJIQAElklObB9cLi9BWjONArwrz7\r
+       Qap4gDEO1/0KaDAT0ODwJj2QwSWJCCmpBsaSHytud/hapggdl51ndOfGN+U1aU8vr9CYNaWs\r
+       rnRWb/drU4HDqWfbH94MM2sT2Kxj9LCKx35f7onw+kNzE96sPuosxsPOtP5f1wtnpxvWk4R2\r
+       TfZbu2Fdu4SIRt2rlUJLDle8PzDH1tlv2sI01VmeZVof1jL2aTx1ZRao3KAtfYzjqcz9NVuV\r
+       WIozEg21mIuKEwE6B/xxrgIAAA==\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: Sun, 23 Mar 2014 21:22:42 -0000\r
+\r
+Without this flush, if stdout is block buffered (which will happen if\r
+it's a pipe or a file, for example) and the hook also writes to\r
+stdout, then notmuch new's output will appear *after* the hook output.\r
+\r
+This situation may be a little esoteric, but it's good practice to\r
+flush before you fork anyway.\r
+---\r
+ hooks.c | 3 +++\r
+ 1 file changed, 3 insertions(+)\r
+\r
+diff --git a/hooks.c b/hooks.c\r
+index 44ee419..662629a 100644\r
+--- a/hooks.c\r
++++ b/hooks.c\r
+@@ -50,6 +50,9 @@ notmuch_run_hook (const char *db_path, const char *hook)\r
+       goto DONE;\r
+     }\r
\r
++    /* Flush any buffered output before forking. */\r
++    fflush (stdout);\r
++\r
+     pid = fork();\r
+     if (pid == -1) {\r
+       fprintf (stderr, "Error: %s hook fork failed: %s\n", hook,\r
+-- \r
+1.8.4.rc3\r
+\r