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