* [PATCH] cli: Flush stdout before fork()ing to run hooks
@ 2014-03-23 21:22 Austin Clements
2014-03-26 0:33 ` David Bremner
0 siblings, 1 reply; 2+ messages in thread
From: Austin Clements @ 2014-03-23 21:22 UTC (permalink / raw)
To: notmuch
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] cli: Flush stdout before fork()ing to run hooks
2014-03-23 21:22 [PATCH] cli: Flush stdout before fork()ing to run hooks Austin Clements
@ 2014-03-26 0:33 ` David Bremner
0 siblings, 0 replies; 2+ messages in thread
From: David Bremner @ 2014-03-26 0:33 UTC (permalink / raw)
To: Austin Clements, notmuch
Austin Clements <amdragon@MIT.EDU> writes:
> 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.
pushed.
d
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-03-26 0:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-23 21:22 [PATCH] cli: Flush stdout before fork()ing to run hooks Austin Clements
2014-03-26 0:33 ` David Bremner
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).