@@ -21,8 +21,8 @@ package Bugzilla::ModPerl;
2121
2222# This sets up our libpath without having to specify it in the mod_perl
2323# configuration.
24- use File::Basename () ;
25- use lib File::Basename:: dirname(__FILE__ );
24+ use File::Basename;
25+ use lib dirname(__FILE__ );
2626use Bugzilla::Constants ();
2727use lib Bugzilla::Constants::bz_locations()-> {' ext_libpath' };
2828
@@ -38,11 +38,17 @@ package Bugzilla::ModPerl;
3838use Apache2::Log ();
3939use Apache2::ServerUtil;
4040use ModPerl::RegistryLoader ();
41- use File::Slurp ();
41+ use File::Basename ();
4242
4343# This loads most of our modules.
4444use Bugzilla ();
45+ # Loading Bugzilla.pm doesn't load this, though, and we want it preloaded.
46+ use Bugzilla::BugMail ();
47+ use Bugzilla::CGI ();
4548use Bugzilla::Extension ();
49+ use Bugzilla::Install::Requirements ();
50+ use Bugzilla::Util ();
51+ use Bugzilla::RNG ();
4652
4753# Make warnings go to the virtual host's log and not the main
4854# server log.
@@ -51,25 +57,6 @@ package Bugzilla::ModPerl;
5157# Pre-compile the CGI.pm methods that we're going to use.
5258Bugzilla::CGI-> compile(qw( :cgi :push) );
5359
54- # Preload all other packages
55- # This works by detecting which packages were loaded at run-time within our
56- # CleanupHandler and writing that list to data/mod_perl_preload.
57- # This ensures that even conditional packages (such as the database handler)
58- # will be pre-loaded.
59- $Bugzilla::extension_packages = Bugzilla::Extension-> load_all();
60- my $data_path = Bugzilla::Constants::bz_locations()-> {datadir };
61- my $preload_file = " $data_path /mod_perl_preload" ;
62- my %preloaded_files ;
63- if (-e $preload_file ) {
64- my @files = File::Slurp::read_file($preload_file , { err_mode => ' carp' });
65- chomp (@files );
66- foreach my $file (@files ) {
67- $preloaded_files {$file } = 1;
68- Bugzilla::Util::trick_taint($file );
69- eval { require $file };
70- }
71- }
72-
7360use Apache2::SizeLimit;
7461# This means that every httpd child will die after processing a request if it
7562# is taking up more than 700MB of RAM all by itself, not counting RAM it is
@@ -105,6 +92,32 @@ package Bugzilla::ModPerl;
10592
10693$server -> add_config([split (" \n " , $conf )]);
10794
95+ # Pre-load all extensions
96+ $Bugzilla::extension_packages = Bugzilla::Extension-> load_all();
97+
98+ # Have ModPerl::RegistryLoader pre-compile all CGI scripts.
99+ my $rl = new ModPerl::RegistryLoader();
100+ # If we try to do this in "new" it fails because it looks for a
101+ # Bugzilla/ModPerl/ResponseHandler.pm
102+ $rl -> {package } = ' Bugzilla::ModPerl::ResponseHandler' ;
103+ my $feature_files = Bugzilla::Install::Requirements::map_files_to_features();
104+
105+ # Prevent "use lib" from doing anything when the .cgi files are compiled.
106+ # This is important to prevent the current directory from getting into
107+ # @INC and messing things up. (See bug 630750.)
108+ no warnings ' redefine' ;
109+ local *lib::import = sub {};
110+ use warnings;
111+
112+ foreach my $file (glob " $cgi_path /*.cgi" ) {
113+ my $base_filename = File::Basename::basename($file );
114+ if (my $feature = $feature_files -> {$base_filename }) {
115+ next if !Bugzilla-> feature($feature );
116+ }
117+ Bugzilla::Util::trick_taint($file );
118+ $rl -> handler($file , $file );
119+ }
120+
108121package Bugzilla::ModPerl::ResponseHandler ;
109122use strict;
110123use base qw( ModPerl::Registry) ;
@@ -141,7 +154,6 @@ sub handler : method {
141154package Bugzilla::ModPerl::CleanupHandler ;
142155use strict;
143156use Apache2::Const -compile => qw( OK) ;
144- use File::Slurp;
145157
146158sub handler {
147159 my $r = shift ;
@@ -153,20 +165,6 @@ sub handler {
153165 delete $r -> pnotes-> {$key };
154166 }
155167
156- # Look for modules loaded post-startup
157- my $dirty = 0;
158- foreach my $file (keys %INC ) {
159- next unless $file =~ / \. pm$ / ;
160- if (not exists $preloaded_files {$file }) {
161- $preloaded_files {$file } = 1;
162- $dirty = 1;
163- }
164- }
165- if ($dirty ) {
166- write_file($preload_file , { atomic => 1, err_mode => ' carp' },
167- join (" \n " , keys %preloaded_files ) . " \n " );
168- }
169-
170168 return Apache2::Const::OK;
171169}
172170
0 commit comments