X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=htetc%2Fhandler.pl;h=cea366134f8d734c4c93f10d46f4c6025715b690;hb=f3c4966ed1f6ec3db7accd6dcdd3a5a3821d72a7;hp=38af4cc8c7c79895607e9e25a9b95e210e99315c;hpb=380df2ee971291598a2b4864a69f067796694b5f;p=freeside.git diff --git a/htetc/handler.pl b/htetc/handler.pl index 38af4cc8c..cea366134 100644 --- a/htetc/handler.pl +++ b/htetc/handler.pl @@ -31,11 +31,30 @@ my $ah = new HTML::Mason::ApacheHandler ( # #chown (Apache->server->uid, Apache->server->gid, $interp->files_written); +my $protect_fds; + sub handler { #($r) = @_; my $r = shift; + #from rt/bin/webmux.pl(.in) + if ( !$protect_fds && $ENV{'MOD_PERL'} && exists $ENV{'MOD_PERL_API_VERSION'} + && $ENV{'MOD_PERL_API_VERSION'} >= 2 + ) { + # under mod_perl2, STDIN and STDOUT get closed and re-opened, + # however they are not on FD 0 and 1. In this case, the next + # socket that gets opened will occupy one of these FDs, and make + # all system() and open "|-" calls dangerous; for example, the + # DBI handle can get this FD, which later system() calls will + # close by putting garbage into the socket. + $protect_fds = []; + push @{$protect_fds}, IO::Handle->new_from_fd(0, "r") + if fileno(STDIN) != 0; + push @{$protect_fds}, IO::Handle->new_from_fd(1, "w") + if fileno(STDOUT) != 1; + } + # If you plan to intermix images in the same directory as # components, activate the following to prevent Mason from # evaluating image files as components. @@ -44,8 +63,8 @@ sub handler ###Module::Refresh->refresh;### - #$r->content_type('text/html; charset=utf-8'); - $r->content_type('text/html; charset=iso-8859-1'); + $r->content_type('text/html; charset=utf-8'); + #$r->content_type('text/html; charset=iso-8859-1'); #eorar my $headers = $r->headers_out; @@ -57,27 +76,31 @@ sub handler if ( $r->filename =~ /\/rt\// ) { #RT - $ah->interp($rt_interp); + # We don't need to handle non-text, non-xml items + return -1 if defined( $r->content_type ) + && $r->content_type !~ m!(^text/|\bxml\b)!io; + local $SIG{__WARN__}; local $SIG{__DIE__}; - RT::Init(); + my_rt_init(); - # We don't need to handle non-text, non-xml items - return -1 if defined( $r->content_type ) - && $r->content_type !~ m!(^text/|\bxml\b)!io; + $ah->interp($rt_interp); } else { local $SIG{__WARN__}; local $SIG{__DIE__}; - RT::Init() if $RT::VERSION; #for lack of something else + my_rt_init(); #we don't want the RT error handlers under FS - undef($SIG{__WARN__}) if defined($SIG{__WARN__}); - undef($SIG{__DIE__}) if defined($SIG{__DIE__} ); + { + no warnings 'uninitialized'; + undef($SIG{__WARN__}) if defined($SIG{__WARN__}); + undef($SIG{__DIE__}) if defined($SIG{__DIE__} ); + } $ah->interp($fs_interp); @@ -105,4 +128,19 @@ sub handler $status; } +my $rt_initialized = 0; + +sub my_rt_init { + return unless $RT::VERSION; + + if ( $rt_initialized ) { + RT::ConnectToDatabase(); + RT::InitSignalHandlers(); + } else { + RT::LoadConfig(); + RT::Init(); + $rt_initialized++; + } +} + 1;