From e25d72159d1ed8a822da3a78ec93885b1bc1b9ba Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Mon, 20 Apr 2015 19:42:54 -0700 Subject: [PATCH] gitweb: support GITWEB_FCGI_NPROC as --nproc alternative If GITWEB_FCGI_NPROC is set to a number, attempt the same FCGI::ProcManager configuration as though it was passed after the --nproc option. This facilitates using FastCGI servers thta do not support passing command line options to the FCGI process but do allow the initial environment to be set. Signed-off-by: Kyle J. McKay --- gitweb/gitweb.perl | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 82197273d6..5aac59200c 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -1282,6 +1282,7 @@ our ($pre_dispatch_hook, $post_dispatch_hook, $pre_listen_hook); our $CGI = 'CGI'; our $cgi; our $fcgi_mode = 0; +our $fcgi_nproc_active = 0; sub configure_as_fcgi { return if $fcgi_mode; @@ -1300,22 +1301,27 @@ sub evaluate_argv { if $script_name =~ /\.fcgi$/ or $auto_fcgi && defined fileno STDIN && fileno STDIN == 0 && getsockname(STDIN); - return unless (@ARGV); - - require Getopt::Long; - Getopt::Long::GetOptions( - 'fastcgi|fcgi|f' => \&configure_as_fcgi, - 'nproc|n=i' => sub { - my ($arg, $val) = @_; - return unless eval { require FCGI::ProcManager; 1; }; - my $proc_manager = FCGI::ProcManager->new({ - n_processes => $val, - }); - our $pre_listen_hook = sub { $proc_manager->pm_manage() }; - our $pre_dispatch_hook = sub { $proc_manager->pm_pre_dispatch() }; - our $post_dispatch_hook = sub { $proc_manager->pm_post_dispatch() }; - }, - ); + my $nproc_sub = sub { + my ($arg, $val) = @_; + return unless eval { require FCGI::ProcManager; 1; }; + $fcgi_nproc_active = 1; + my $proc_manager = FCGI::ProcManager->new({ + n_processes => $val, + }); + our $pre_listen_hook = sub { $proc_manager->pm_manage() }; + our $pre_dispatch_hook = sub { $proc_manager->pm_pre_dispatch() }; + our $post_dispatch_hook = sub { $proc_manager->pm_post_dispatch() }; + }; + if (@ARGV) { + require Getopt::Long; + Getopt::Long::GetOptions( + 'fastcgi|fcgi|f' => \&configure_as_fcgi, + 'nproc|n=i' => $nproc_sub, + ); + }; + if (!$fcgi_nproc_active && defined $ENV{'GITWEB_FCGI_NPROC'} && $ENV{'GITWEB_FCGI_NPROC'} =~ /^\d+$/) { + &$nproc_sub('nproc', $ENV{'GITWEB_FCGI_NPROC'}); + } } sub run { -- 2.11.4.GIT