all repos — cgit @ 3b485cc5422f800d142c7023295e82c0a1c10b19

a hyperfast web frontend for git written in c

cache: flush stdio before restoring FDs

As described in commit 2efb59e (ui-patch: Flush stdout after outputting
data, 2014-06-11), we need to ensure that stdout is flushed before
restoring the file descriptor when writing to the cache.  It turns out
that it's not just ui-patch that is affected by this but also raw diff
which writes to stdout internally.

Let's avoid risking more places doing this by ensuring that stdout is
flushed after writing in fill_slot().

Signed-off-by: John Keeping <john@keeping.me.uk>
John Keeping john@keeping.me.uk
Mon, 24 Apr 2017 19:38:34 +0100
commit

3b485cc5422f800d142c7023295e82c0a1c10b19

parent

de297883385030f4bdcd2f5c3839d1187611b949

2 files changed, 6 insertions(+), 2 deletions(-)

jump to
M cache.ccache.c

@@ -224,6 +224,12 @@

/* Generate cache content */ slot->fn(); + /* Make sure any buffered data is flushed to the file */ + if (fflush(stdout)) { + close(tmp); + return errno; + } + /* update stat info */ if (fstat(slot->lock_fd, &slot->cache_st)) { close(tmp);
M ui-patch.cui-patch.c

@@ -92,6 +92,4 @@ while ((commit = get_revision(&rev)) != NULL) {

log_tree_commit(&rev, commit); printf("-- \ncgit %s\n\n", cgit_version); } - - fflush(stdout); }