From 532b51863d1d651ba51bfc7d99e537b5713f0aad Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Fri, 10 Apr 2015 20:36:28 -0700 Subject: [PATCH] gitweb: make htmlcache compatible with FCGI mode When running in FCGI mode, the STDOUT file handle is not necessarily related to the STDOUT_FILENO file descriptor in any way. In order to capture the created output for caching, we need to point the STDOUT file handle to the cache file. Rather than attempting to use file descriptor operators on it (which will only work if it's associated with a real file descriptor), just replace the entire typeglob with a new file handle and restore the old one when done. This works properly whether we are running in FCGI mode or not. Signed-off-by: Kyle J. McKay --- gitweb/gitweb.perl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 589fae67bc..002cbdaabe 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -1769,8 +1769,7 @@ sub cached_action_start { my $cache_file = "$projectroot/$project/$html_cache_dir/$action"; sysopen(CACHEFILE, "$cache_file.lock", O_WRONLY|O_CREAT|O_EXCL, 0664) or return undef; - open(STDOUT, ">&CACHEFILE") || die "couldn't dup CACHEFILE: $!"; - close(CACHEFILE) or die "couldn't close CACHEFILE: $!"; + *STDOUT = *CACHEFILE; unlink "$cache_file.changed"; return 1; } @@ -1785,7 +1784,9 @@ sub cached_action_finish { my $cache_file = "$projectroot/$project/$html_cache_dir/$action"; close(STDOUT) or die "couldn't close cache file on STDOUT: $!"; # Do not leave STDOUT file descriptor invalid! - open(STDOUT, '>', File::Spec->devnull) or die "couldn't reopen STDOUT to devnull: $!"; + local *NULL; + open(NULL, '>', File::Spec->devnull) or die "couldn't open NULL to devnull: $!"; + *STDOUT = *NULL; unlink "$cache_file.lock" unless rename "$cache_file.lock", $cache_file; return cached_action_page($action, 1); } @@ -6582,8 +6583,7 @@ sub git_project_index { sub git_summary { my $cached_page = cached_action_page('summary'); print($cached_page), return if $cached_page; - local *SAVEOUT; - open(SAVEOUT, ">&STDOUT") || die "couldn't dup STDOUT: $!"; + local *SAVEOUT = *STDOUT; my $caching_page = cached_action_start('summary'); SUMMARY_CACHE_FAIL: @@ -6705,7 +6705,7 @@ SUMMARY_CACHE_FAIL: if ($caching_page) { $cached_page = cached_action_finish('summary'); - open(STDOUT, ">&SAVEOUT") || die "couldn't dup SAVEOUT: $!"; + *STDOUT = *SAVEOUT; if (!$cached_page) { # Some other failure, redo without cache $caching_page = 0; -- 2.11.4.GIT