From mboxrd@z Thu Jan 1 00:00:00 1970 From: mricon at kernel.org (Konstantin Ryabitsev) Date: Mon, 25 Sep 2017 08:51:06 -0400 Subject: [PATCH] cache: flush stdio before restoring FDs In-Reply-To: <20170424185240.GB1788@john.keeping.me.uk> References: <20170424155440.GB15623@gmail.com> <20170424185240.GB1788@john.keeping.me.uk> Message-ID: <20170925125106.GA4200@gmail.com> Hi, all: As far as I can tell, the fix for this is still not in any released version of cgit, so the rawdiff cache truncation bug is still present in the latest release (as I just found out because EPEL's cgit has the unpatched version of the package). Best, -K On Mon, Apr 24, 2017 at 07:52:40PM +0100, John Keeping wrote: >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 >--- >On Mon, Apr 24, 2017 at 11:54:40AM -0400, Konstantin Ryabitsev wrote: >> Very reminiscent of a fix for ui-patch.c that fixed patch truncation [1] >> there's a similar problem with cached rawdiff output. E.g.: >> >> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/rawdiff/?id=v4.11-rc7&id2=v4.11-rc8 >> >> You will notice that the output is truncated (if it isn't just reload to >> get the cached version). >> >> I would love a speedy fix, as we're trying to use this in place of >> publishing pre-generated patches. > >I guess it's the same problem we fixed before for ui-patch, so here's a >patch to move the fix into the common path for all pages. > > cache.c | 6 ++++++ > ui-patch.c | 2 -- > 2 files changed, 6 insertions(+), 2 deletions(-) > >diff --git a/cache.c b/cache.c >index 6736a01..2ccdc4e 100644 >--- a/cache.c >+++ b/cache.c >@@ -224,6 +224,12 @@ static int fill_slot(struct cache_slot *slot) > /* 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); >diff --git a/ui-patch.c b/ui-patch.c >index 047e2f9..6745b69 100644 >--- a/ui-patch.c >+++ b/ui-patch.c >@@ -92,6 +92,4 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, > log_tree_commit(&rev, commit); > printf("-- \ncgit %s\n\n", cgit_version); > } >- >- fflush(stdout); > }