Skip to content

Commit a0446e7

Browse files
Sam Vilaingitster
authored andcommitted
gitweb: Add support for FastCGI, using CGI::Fast
Former run() subroutine got renamed to run_request(). The new run() subroutine can run multiple requests at once if run as FastCGI script. To run gitweb as FastCGI script you must specify '--fastcgi' / '-f' command line option to gitweb, otherwise it runs as an ordinary CGI script. [jn: cherry picked from 56d7d436644ab296155a697552ea1345f2701620 in http://utsl.gen.nz/gitweb/?p=gitweb which was originally based on v264 (2326acf) by Kay Sievers; updated to reflect current gitweb code] TODO: update 'gitweb/README' and/or 'gitweb/INSTALL' files. Signed-off-by: Sam Vilain <sam.vilain@catalyst.net.nz> Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent c2394fe commit a0446e7

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

gitweb/gitweb.perl

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ sub dispatch {
999999
$actions{$action}->();
10001000
}
10011001

1002-
sub run {
1002+
sub run_request {
10031003
our $t0 = [Time::HiRes::gettimeofday()]
10041004
if defined $t0;
10051005

@@ -1019,11 +1019,61 @@ sub run {
10191019
configure_gitweb_features();
10201020

10211021
dispatch();
1022+
}
1023+
1024+
our $is_last_request = sub { 1 };
1025+
our ($pre_dispatch_hook, $post_dispatch_hook, $pre_listen_hook);
1026+
our $CGI = 'CGI';
1027+
our $cgi;
1028+
sub evaluate_argv {
1029+
return unless (@ARGV);
1030+
1031+
require Getopt::Long;
1032+
Getopt::Long::GetOptions(
1033+
'fastcgi|fcgi|f' => sub {
1034+
require CGI::Fast;
1035+
our $CGI = 'CGI::Fast';
1036+
1037+
my $request_number = 0;
1038+
# let each child service 100 requests
1039+
our $is_last_request = sub { ++$request_number > 100 };
1040+
},
1041+
'nproc|n=i' => sub {
1042+
my ($arg, $val) = @_;
1043+
return unless eval { require FCGI::ProcManager; 1; };
1044+
my $proc_manager = FCGI::ProcManager->new({
1045+
n_processes => $val,
1046+
});
1047+
our $pre_listen_hook = sub { $proc_manager->pm_manage() };
1048+
our $pre_dispatch_hook = sub { $proc_manager->pm_pre_dispatch() };
1049+
our $post_dispatch_hook = sub { $proc_manager->pm_post_dispatch() };
1050+
},
1051+
);
1052+
}
1053+
1054+
sub run {
1055+
evaluate_argv();
1056+
1057+
$pre_listen_hook->()
1058+
if $pre_listen_hook;
1059+
1060+
REQUEST:
1061+
while ($cgi = $CGI->new()) {
1062+
$pre_dispatch_hook->()
1063+
if $pre_dispatch_hook;
1064+
1065+
run_request();
1066+
1067+
$pre_dispatch_hook->()
1068+
if $post_dispatch_hook;
1069+
1070+
last REQUEST if ($is_last_request->());
1071+
}
10221072

10231073
DONE_GITWEB:
10241074
1;
10251075
}
1026-
our $cgi = CGI->new();
1076+
10271077
run();
10281078

10291079
## ======================================================================

0 commit comments

Comments
 (0)