You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Dave Rolsky <au...@urth.org> on 2000/11/29 09:43:13 UTC

segmentation fault when using custom config module

Relevant info:

Apache: 1.3.12
mod_perl: 1.24
Perl: 5.00503
gcc 2.95.1 on Linus 2.2.18pre19


I created a module that contains custom configs with the following code:

package HTML::Mason::Dispatcher;

use ExtUtils::MakeMaker;
use Apache::ExtUtils;
use Apache::src;

my @directives = ( { name => 'MasonCompRoot',
		     errmsg => 'The directory that is the Mason component
root',
		     args_how => 'TAKE1',
		     req_override => 'RSRC_CONF',
		   },
		   { name => 'MasonDataDir',
		     errmsg => 'The Mason data directory',
		     args_how => 'TAKE1',
		     req_override => 'RSRC_CONF',
		   },
		   { name => 'MasonArgsMethod',
		     errmsg => 'The method used to process arguments (CGI.pm or mod_perl)',
		     args_how => 'TAKE1',
		     req_override => 'RSRC_CONF',
		   },
		 );

local $^W;
Apache::ExtUtils::command_table(\@directives);

WriteMakefile( NAME    => 'HTML::Mason::Dispatcher',
	       VERSION_FROM => 'Dispatcher.pm',
	       INC => Apache::src->new->inc,
	     );

----------------------------------------------------

The Dispatcher.pm files contains the following code:

package HTML::Mason::Dispatcher;

use strict;

use Apache::ModuleConfig ();
use DynaLoader ();
use HTML::Mason;

use vars qw($VERSION $AH @ISA);

$VERSION = '0.01';

@ISA = qw(DynaLoader);

use constant DEBUG => 1;

__PACKAGE__->bootstrap($VERSION) if $ENV{MOD_PERL};

sub MasonCompRoot ($$$)
{
    my ($cfg, $params, $comp_root) = @_;
    $cfg->{Mason}{comp_root} = $comp_root;
}

sub MasonDataDir ($$$)
{
    my ($cfg, $params, $data_dir) = @_;
    $cfg->{Mason}{data_dir} = $data_dir;
}

sub MasonArgsMethod ($$$)
{
    my ($cfg, $params, $method) = @_;
    unless ( $method eq 'CGI' || $method eq 'mod_perl' )
    {
	die "Invalid MasonArgsMethod param: $method\n";
    }
    eval "use HTML::Mason::ApacheHandler ( args_method => '$method' )";
    die $@ if $@;
}

sub handler
{
    eval "use HTML::Mason::ApacheHandler;" unless $HTML::Mason::ApacheHandler::VERSION;

    my $r = shift;
    unless ($AH)
    {
	my $cfg = Apache::ModuleConfig->get($r);
	my $interp = HTML::Mason::Interp->new( parser => HTML::Mason::Parser->new,
					       comp_root => $cfg->{Mason}{comp_root},
					       data_dir => $cfg->{Mason}{data_dir} );
	$AH = HTML::Mason::ApacheHandler( interp => $interp );
    }

    return $AH->handle_request($r);
}

----------------------------------------------

My config file contains the following:


<Perl>
use lib '/home/autarch/mason-CVS/mason/dist/lib';
</Perl>
PerlModule HTML::Mason::Dispatcher

MasonCompRoot /usr/local/apache/htdocs
MasonDataDir /usr/local/apache_mp/mason
MasonArgsMethod mod_perl

<FilesMatch "\.mhtml$">
    SetHandler perl-script
    PerlHandler HTML::Mason::Dispatcher
</FilesMatch>

-----------------------------------------------

Anyway, the configuration directives piece works fine.  I added warn
statements in the relevant functions and it confirmed that were indeed
being called with the correct values.

However, when I make a request to a URL that would call the handler
method, I get a segmentation fault.

I recompiled mod_perl with tracing and set MOD_PERL_TRACE=all.  The trace
was pretty uninteresting.  Here's what I got when starting the server:

perl_parse args: '-w' '/dev/null' ...allocating perl interpreter...ok
constructing perl interpreter...ok
ok
running perl interpreter...ok
mod_perl: 0 END blocks encountered during server startup
loading perl module 'Apache'...loading perl module
'Apache::Constants::Exports'...ok
ok
loading perl module 'Tie::IxHash'...ok
perl_section: </Files>
perl_section: </Directory>
perl_section: </Files>
perl_section: </Directory>
perl_section: </VirtualHost>
perl_section: </Location>
perl_section: </Location>
loading perl module 'Apache'...ok
PerlModule: arg='HTML::Mason::Dispatcher'
loading perl module 'HTML::Mason::Dispatcher'...ok
bootstrapping <Perl> sections: arg=HTML::Mason::Dispatcher, keys=10
loading perl module 'Apache'...ok
loading perl module 'Tie::IxHash'...ok
perl_section: </Files>
perl_section: </Directory>
perl_section: </Files>
perl_section: </Directory>
perl_section: </VirtualHost>
perl_section: </Location>
perl_section: </Location>
mod_perl: delete $INC{'HTML/Mason/Dispatcher.pm'} (klen=24)
blessing cmd_parms=(0xbffffab4)
blessing cmd_parms=(0xbffffab4)
blessing cmd_parms=(0xbffffab4)
init `PerlHandler' stack
perl_cmd_push_handlers: @PerlHandler, 'HTML::Mason::Dispatcher'
pushing `HTML::Mason::Dispatcher' into `PerlHandler' handlers

----------------------------------------

And here's what's in the error_log file:

`PerlRestartHandler' push_handlers() stack is empty
PerlRestartHandler handlers returned -1
[Wed Nov 29 02:40:08 2000] [notice] Apache/1.3.12 (Unix) mod_perl/1.24 configured -- resuming normal operations
perl_init_ids: uid=500, euid=500, gid=100, egid=100
`PerlChildInitHandler' push_handlers() stack is empty
PerlChildInitHandler handlers returned -1
perl_init_ids: uid=500, euid=500, gid=100, egid=100
`PerlChildInitHandler' push_handlers() stack is empty
PerlChildInitHandler handlers returned -1
`PerlInitHandler' push_handlers() stack is empty
PerlInitHandler handlers returned -1
`PerlPostReadRequestHandler' push_handlers() stack is empty
PerlPostReadRequestHandler handlers returned -1
[Wed Nov 29 02:40:30 2000] [notice] child pid 12127 exit signal
Segmentation fault (11)
perl_init_ids: uid=500, euid=500, gid=100, egid=100
`PerlChildInitHandler' push_handlers() stack is empty
PerlChildInitHandler handlers returned -1


Help would be appreciated.


-dave


Re: segmentation fault when using custom config module

Posted by Doug MacEachern <do...@covalent.net>.
On Wed, 29 Nov 2000, Dave Rolsky wrote:
 
> I created a module that contains custom configs with the following code:

i cannot reproduce this with or without the patch just posted.
i did have to change this line for it to run:
	$AH = HTML::Mason::ApacheHandler( interp => $interp );
to:
        $AH = HTML::Mason::ApacheHandler->new( interp => $interp );

but it only caused a server error, no core dump.  give the patch a shot
anyhow, if you're still having this problem, we'll need a stack trace (see
SUPPORT).


Re: segmentation fault when using custom config module

Posted by Dave Rolsky <au...@urth.org>.
On Wed, 29 Nov 2000, Matt Sergeant wrote:

> On Wed, 29 Nov 2000, Dave Rolsky wrote:
>
> > 	my $cfg = Apache::ModuleConfig->get($r);
>
> Try:
>
> my $cfg = Apache::ModuleConfig->get($r, __PACKAGE__);

I should have said that its segfaulting before it ever gets into the
handler sub.  I changed handler to:

sub handler
{
    warn "HANDLER\n";
}

and it still segfaulted.


-dave

/*==================
www.urth.org
We await the New Sun
==================*/


Re: segmentation fault when using custom config module

Posted by Matt Sergeant <ma...@sergeant.org>.
On Wed, 29 Nov 2000, Dave Rolsky wrote:

> 	my $cfg = Apache::ModuleConfig->get($r);

Try:

my $cfg = Apache::ModuleConfig->get($r, __PACKAGE__);

-- 
<Matt/>

    /||    ** Director and CTO **
   //||    **  AxKit.com Ltd   **  ** XML Application Serving **
  // ||    ** http://axkit.org **  ** XSLT, XPathScript, XSP  **
 // \\| // **     Personal Web Site: http://sergeant.org/     **
     \\//
     //\\
    //  \\