pjotrik has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,
i just encountered a very strange Apache/modperl behavior, I'll be happy if someone can explain why things happened the way they did.

I have an Apache2 mod perl handler, somewhere deeper inside this module is used:

package SynAdmin::Response; use base 'SynAdmin'; use warnings; use strict; sub print { my ($self) = @_; $$self{r}->content_type('text/plain'); $self->tpl_proc()->process('main.tpl', $self{data}, $$self{r}) +; } 1;

As you can see, there's an error - a missing $ in $self{data}. The weird thing is, when I restarted the server to activate this changed module, Apache crashed with /usr/sbin/apachectl: line 91: 18435 Segmentation fault      $HTTPD $OPTIONS -t. Usually when there's a syntax error in my code, Apache passes on the perl error message. Can anyone tell why not in this case?

Server Version: Apache/2.2.8 (Unix) DAV/2 mod_apreq2-20051231/2.6.1 mod_perl/2.0.3 Perl/v5.8.8

Any comments are appreciated!

Update: If I change the $self{data} into a simple $x, I get the Global symbol "$x" requires explicit package name I'd expect and it propagates well through.

Replies are listed 'Best First'.
Re: Handler syntax error causes an apache segfault during startup
by ursus (Acolyte) on Jul 06, 2008 at 01:32 UTC
    To start with, I'd suggest switching from $$href{key} syntax to $href->{key}. Let's see what happens from there. ;-)

      Well of course, correcting to $self->{data} removes the error as well as correcting to $$self{data}. With this error fixed, apache starts correctly - the issue is that it doesn't report the syntax error very nicely.

      From some further experimentation, the Apache segfault really only seems to happen when there's an undeclared hash. Other kinds of syntax errors I could come up with are reported correctly.

Re: Handler syntax error causes an apache segfault during startup
by LesleyB (Friar) on Jul 09, 2008 at 11:10 UTC

    Hi

    I don't know the innards of Apache, mod_perl or how modules work with Apache, and you may have already realised the core of the problem.

    You have a hash ref, $self, and attempt to access $self{data}. Because of my C history I tend to regard references as pointers to something.

    So when you use $self you are using the pointer itself, when you use $$self you are accessing what the pointer points to; in perl speak I think this is dereferencing.

    $self is not undefined or NULL, but the dereferencing isn't happening so we have no idea what $self{data} attempts to retrieve.

    The {data} part will probably be translating to an offset memory address using $self as the starting point.

    So you start where the pointer is and then select a piece of memory near it when you really meant to start at the piece of memory the pointer points to and then select the memory near that.

    There's no knowing what you are attempting to access but, in C, the attempt might well throw a segmentation fault.

    The issue you have is that it isn't being trapped

    Do you know if it is repeatable with another data set and another machine and OS?