[PATCH] cli: Flush stdout before fork()ing to run hooks

Subject: [PATCH] cli: Flush stdout before fork()ing to run hooks

Date: Sun, 23 Mar 2014 17:22:26 -0400

To: notmuch@notmuchmail.org

Cc:

From: Austin Clements


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


Thread: