From: Austin Clements Date: Sun, 23 Mar 2014 21:22:26 +0000 (-0400) Subject: cli: Flush stdout before fork()ing to run hooks X-Git-Tag: 0.18_rc0~64 X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=commitdiff_plain;h=03680d10066f85887c1198925a7b297b27435919;hp=31a6333aa46fc8125d2fe1effd6fddf48e47c14e cli: Flush stdout before fork()ing to run hooks 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. --- diff --git a/hooks.c b/hooks.c index 44ee4198..662629a9 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,