]> git.cworth.org Git - notmuch/commitdiff
cli: Flush stdout before fork()ing to run hooks
authorAustin Clements <amdragon@MIT.EDU>
Sun, 23 Mar 2014 21:22:26 +0000 (17:22 -0400)
committerDavid Bremner <david@tethera.net>
Wed, 26 Mar 2014 00:22:17 +0000 (21:22 -0300)
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

diff --git a/hooks.c b/hooks.c
index 44ee41980085c5383c8f9d617fa63764d410110f..662629a951b309021cb86eebfbb0d0cca345e8d0 100644 (file)
--- 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,