1
0
mirror of https://gitea.quitesimple.org/crtxcr/cgitsb synced 2024-11-26 11:33:47 +01:00

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>
This commit is contained in:
John Keeping 2017-04-24 19:38:34 +01:00
parent de29788338
commit 3b485cc542
2 changed files with 6 additions and 2 deletions

@ -224,6 +224,12 @@ static int fill_slot(struct cache_slot *slot)
/* Generate cache content */ /* Generate cache content */
slot->fn(); slot->fn();
/* Make sure any buffered data is flushed to the file */
if (fflush(stdout)) {
close(tmp);
return errno;
}
/* update stat info */ /* update stat info */
if (fstat(slot->lock_fd, &slot->cache_st)) { if (fstat(slot->lock_fd, &slot->cache_st)) {
close(tmp); close(tmp);

@ -92,6 +92,4 @@ void cgit_print_patch(const char *new_rev, const char *old_rev,
log_tree_commit(&rev, commit); log_tree_commit(&rev, commit);
printf("-- \ncgit %s\n\n", cgit_version); printf("-- \ncgit %s\n\n", cgit_version);
} }
fflush(stdout);
} }