PerlConfigRequire and die
PerlConfigRequire and die
am 23.02.2009 15:32:40 von Clinton Gormley
Hiya
I'm using PerlConfigRequire to load my Perl application, which also sets
up the VirtualHost's using $r->add_config()
The problem is, if one my modules has a compile time error, instead of
getting the real error message, I get something like this:
---------------------------------------------------------
Syntax error on line 266 of /opt/apache/conf/httpd.conf:
`l\xa6\x02
---------------------------------------------------------
I realise that PerlPostConfigRequire should normally be used in
preference to PerlConfigRequire, but because I need to alter apache's
config, this isn't an option.
If I change my code in startup.pl from:
load_application();
1;
to:
eval {load_application(); 1} || print STDERR $@;
1;
then I see the proper error message, but apache starts anyway.
Die'ing or returning 0 both result in this weird error.
Is there any way I can:
- cause the error to be reported properly
- force apache not to start
thanks
Clint
Re: PerlConfigRequire and die
am 23.02.2009 22:24:20 von Mark Hedges
On Mon, 23 Feb 2009, Clinton Gormley wrote:
> to:
> eval {load_application(); 1} || print STDERR $@;
> 1;
>
> then I see the proper error message, but apache starts
> anyway.
>
> Is there any way I can:
> - cause the error to be reported properly
> - force apache not to start
eval {load_application(); 1} || do { warn $@; die };
??
Mark
Re: PerlConfigRequire and die
am 26.02.2009 12:06:45 von Clinton Gormley
> >
> > Is there any way I can:
> > - cause the error to be reported properly
> > - force apache not to start
> eval {load_application(); 1} || do { warn $@; die };
Unfortunately, no. That still just dies with the obscure error message.
It seems that STDERR only gets flushed in a later stage of the startup
process.
What I was thinking was, could there be some way of saying:
eval { load_application();1}
|| do {
warn $@;
force_apache_to_quit_startup_once_stderr_flushed();
}
clint
Re: PerlConfigRequire and die
am 26.02.2009 15:50:43 von torsten.foertsch
On Thu 26 Feb 2009, Clinton Gormley wrote:
> > > Is there any way I can:
> > > =A0- cause the error to be reported properly
> > > =A0- force apache not to start
> >
> > =A0eval {load_application(); 1} || do { warn $@; die };
>
> Unfortunately, no. =A0That still just dies with the obscure error
> message. It seems that STDERR only gets flushed in a later stage of
> the startup process.
>
> What I was thinking was, could there be some way of saying:
>
> eval { load_application();1}
> =A0 || do {
> =A0 =A0 =A0 =A0 =A0 warn $@;
> =A0 =A0 =A0 =A0 =A0 force_apache_to_quit_startup_once_stderr_flushed();
> =A0 =A0 =A0}
Why don't you do that in a block?
Be aware that this code is executed twice at startup. Check=20
Apache2::ServerUtil::restart_count to prevent that.
Torsten
=2D-=20
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net
Re: PerlConfigRequire and die
am 26.02.2009 16:06:19 von Clinton Gormley
> > eval { load_application();1}
> > || do {
> > warn $@;
> > force_apache_to_quit_startup_once_stderr_flushed();
> > }
>
> Why don't you do that in a block?
How is this different from doing it in the startup.pl file?
>
> Be aware that this code is executed twice at startup. Check
> Apache2::ServerUtil::restart_count to prevent that.
Yes, as my app takes a while to load, so I'm actually only loading when
I really need to:
return 1
if $apache_mode
&& ( $apache_mode eq 'restart'
&& Apache2::ServerUtil::restart_count() == 1
|| $apache_mode !~ /start/ );
(where $apache_mode is set from the command line arg to apachectl)
However, I still get this same obscure error whether I use that code or
not, eg:
Syntax error on line 266 of /opt/apache/conf/httpd.conf:
\xf0\x9a\x83
thanks
Clint
Re: PerlConfigRequire and die
am 27.02.2009 18:25:05 von torsten.foertsch
On Thu 26 Feb 2009, Clinton Gormley wrote:
> > Why don't you do that in a block?
>
> How is this different from doing it in the startup.pl file? =A0
Yes, I see, the 2nd run of the code doesn't have STDERR either.=20
So, you can open a startup logfile in perl and override=20
CORE::GLOBAL::warn/die or install a $SIG{__WARN__/__DIE__} handler. Or=20
even open that logfile at start of your startup.pl on file descriptor 2=20
and close it at the end.
use Apache2::ServerUtil;
if( Apache2::ServerUtil::restart_count>1 ) {
open my $olderr, '>&', \*STDERR;
close STDERR;
open STDERR, '>', '/tmp/myerr';
# initialize your app here
warn "huhu";
print STDERR "haha";
# end of init
close STDERR;
open STDERR, '>&', $olderr;
}
Torsten
=2D-=20
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net
Re: PerlConfigRequire and die [solved]
am 28.02.2009 18:26:25 von Clinton Gormley
On Mon, 2009-02-23 at 15:32 +0100, Clinton Gormley wrote:
> Hiya
>
> I'm using PerlConfigRequire to load my Perl application, which also sets
> up the VirtualHost's using $r->add_config()
>
> The problem is, if one my modules has a compile time error, instead of
> getting the real error message, I get something like this:
>
> ---------------------------------------------------------
> Syntax error on line 266 of /opt/apache/conf/httpd.conf:
> `l\xa6\x02
> ---------------------------------------------------------
Turns out it was my $SIG{__DIE__} handler which was causing the problem.
I added a handler to inflate uncaught errors into an object exception,
so it could give me a nice stack trace.
>From the perlvar POD:
__DIE__ /__WARN__ handlers are very special in one respect: they may be
called to report (probable) errors found by the parser. In such a case
the parser may be in inconsistent state, so any attempt to evaluate Perl
code from such a handler will probably result in a segfault. This means
that warnings or errors that result from parsing Perl should be used
with extreme caution...
So by using:
local $SIG{__DIE__};
before requiring modules, this issue has been sorted out.
thanks to all who gave advice.
clint