| 1 | #! /usr/bin/perl | ||
| 2 | package RWDE::Web::FCGIadapter; | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | |||
| 7 | use CGI; | ||
| 8 | use FCGI; | ||
| 9 | |||
| 10 | use Error qw(:try); | ||
| 11 | |||
| 12 | use RWDE::Exceptions; | ||
| 13 | |||
| 14 | use base qw(CGI RWDE::Web::CGIadapter); | ||
| 15 | |||
| 16 | our($Ext_Request); | ||
| 17 | |||
| 18 | use vars qw($VERSION); | ||
| 19 | $VERSION = sprintf "%d", q$Revision: 566 $ =~ /(\d+)/; | ||
| 20 | |||
| 21 | # workaround for known bug in libfcgi | ||
| 22 | while ((my $ignore) = each %ENV) { } | ||
| 23 | |||
| 24 | # set up the FCGI connection. called from superclass new() method | ||
| 25 | # calls FCGI's accept() method. | ||
| 26 | sub initialize { | ||
| 27 | my ($self, $params) = @_; | ||
| 28 | |||
| 29 | if ($Ext_Request) { | ||
| 30 | return unless $Ext_Request->Accept() >= 0; | ||
| 31 | } else { | ||
| 32 | return unless FCGI::accept() >= 0; | ||
| 33 | } | ||
| 34 | |||
| 35 | CGI->_reset_globals; | ||
| 36 | |||
| 37 | $self->{req} = $CGI::Q = CGI->new($params); | ||
| 38 | |||
| 39 | return; | ||
| 40 | } | ||
| 41 | |||
| 42 | # override the initialization behavior so that | ||
| 43 | # state is NOT maintained between invocations | ||
| 44 | sub save_request { | ||
| 45 | # no-op | ||
| 46 | } | ||
| 47 | |||
| 48 | sub run { | ||
| 49 | my ($self, $params) = @_; | ||
| 50 | |||
| 51 | # it should fork here and enter the blocking while loop | ||
| 52 | # for the child only, the parent should make note who | ||
| 53 | # got deployed listening to which port and continue monitoring | ||
| 54 | |||
| 55 | while (my $req = $self->new()) { | ||
| 56 | try{ | ||
| 57 | RWDE::Web::CommandProxy->execute({ req => $req }); | ||
| 58 | } | ||
| 59 | |||
| 60 | catch Error with{ | ||
| 61 | my $ex = shift; | ||
| 62 | |||
| 63 | $self->syslog_msg('info', "dispatch caught: $ex"); | ||
| 64 | $self->syslog_msg('info', "This is beyond unusual, exceptions are caught here to avoid server going down"); | ||
| 65 | } | ||
| 66 | |||
| 67 | } | ||
| 68 | |||
| 69 | return(); | ||
| 70 | } | ||
| 71 | |||
| 72 | |||
| 73 | 1; |