You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Jeff Pang <pa...@earthlink.net> on 2007/12/13 05:36:34 UTC
help about Apache::Scoreboard
When added these code in my handler:
my $r = shift;
# We decline to handle subrequests: otherwise, a few lines down we
# could get into an infinite loop.
return DECLINED unless $r->is_initial_req;
#
# for limit-ip-conn
#
my $ip_count = 0;
my $limit = $r->dir_config('MaxConnPerIP') || 0;
my $ip = $r->connection->remote_ip;
my $host = $r->connection->remote_host;
my $image = Apache::Scoreboard->image;
for (my $parent = $image->parent; $parent; $parent = $parent->next) {
my $server = $parent->server;
next if ($server->status =~ /^[\._SL]$/);
if (($ip eq $server->client) or ($host eq $server->client)) {
$ip_count++;
}
}
if ($ip_count > $limit and $limit) {
$r->log_reason("Client exceeded connection limit.", $r->filename);
return FORBIDDEN;
}
I got many warnings in error_log:
Use of uninitialized value in string eq at /opt/apache1.3/run/DLAuth.pm line 42.
at /opt/apache1.3/run/DLAuth.pm line 42
DLAuth::handler('Apache=SCALAR(0x91cbe8c)') called at /dev/null line 0
eval {...} called at /dev/null line 0
The line 42 is:
if (($ip eq $server->client) or ($host eq $server->client)) {
And the handler (PerlAccessHandler) seems work not correctly.
Please guide, thanks.
Re: help about Apache::Scoreboard
Posted by Jeff Pang <pa...@earthlink.net>.
2007/12/14, Malcolm <mj...@liminalflux.net>:
> On Thursday 13 December 2007 10:00:30 am Jeff Pang wrote:
>
> > right now I got these exceptions in error_log:
> >
> > [Thu Dec 13 21:53:49 2007] [notice] child pid 4660 exit signal
> > Segmentation fault (11)
>
> Apache::Scoreboard is basically just a wrapper around the apache scoreboard
> api, so we're dealing with the C layer for the most part not the perl layer.
> The seg faults suggests we're wandering off a bad pointer somewhere. :-(
>
> Did you try running apache under a debugger to see where it's segfaulting?
>
Not yet. It happened only on product servers, for test server I didn't
get the errors. but test server doesn't get real users' access.
> > This is my full code (the key string for generating md5 is replaced
> > here for privacy reasons):
>
> Can you cut this down to just the Apache::Scoreboard using code? That way we
> can be sure that's what is causing the problem.
>
The Apache::Scoreboard code had included in my before message, which
is not long, :)
>
> and see what's in the logs.
>
ok i'll follow your suggestion to see what happened.
>
> Did you do any of the following from my previous email?
>
Yes I did.
>
> What are the values of $ip, $host and $server->client at that point?
> The "uninitialised value" could be any of the above.
>
I found the problem, the $host seems most time get uninitialised value.
so I comment out the code lines for $host, and it works.
> > And the handler (PerlAccessHandler) seems work not correctly.
>
> Does it work as a perl request handler? (PerlHandler for mp1).
> Can you get any values at all out of the ServerScore instance?
>
I didn't try PerlHandler. I need a PerlAccessHandler actually.
Thanks for the responce.
Re: help about Apache::Scoreboard
Posted by Malcolm <mj...@liminalflux.net>.
On Thursday 13 December 2007 10:00:30 am Jeff Pang wrote:
> right now I got these exceptions in error_log:
>
> [Thu Dec 13 21:53:49 2007] [notice] child pid 4660 exit signal
> Segmentation fault (11)
Apache::Scoreboard is basically just a wrapper around the apache scoreboard
api, so we're dealing with the C layer for the most part not the perl layer.
The seg faults suggests we're wandering off a bad pointer somewhere. :-(
Did you try running apache under a debugger to see where it's segfaulting?
> This is my full code (the key string for generating md5 is replaced
> here for privacy reasons):
Can you cut this down to just the Apache::Scoreboard using code? That way we
can be sure that's what is causing the problem.
Try this:
> use strict;
> use warnings;
> use Apache::Constants qw(OK FORBIDDEN DECLINED);
> use Apache::Request ();
> use Apache::Scoreboard ();
> use Apache qw(exit);
>
> sub handler {
>
> my $r = shift;
> my $image = Apache::Scoreboard->image;
>
> for (my $parent = $image->parent; $parent; $parent = $parent->next) {
warn "parent pid: " . $parent->pid;
> my $server = $parent->server;
warn "server: " . $server; # just to prove we're not undef here
warn "- status: " . $server->status;
warn "- client: " . $server->client;
> }
> }
>
> return OK;
> }
>
> 1;
and see what's in the logs.
Did you do any of the following from my previous email?
> I got many warnings in error_log:
>
> Use of uninitialized value in string eq at /opt/apache1.3/run/DLAuth.pm
> line 42. at /opt/apache1.3/run/DLAuth.pm line 42
> DLAuth::handler('Apache=SCALAR(0x91cbe8c)') called at /dev/null
> line 0 eval {...} called at /dev/null line 0
>
> The line 42 is:
> if (($ip eq $server->client) or ($host eq $server->client)) {
What are the values of $ip, $host and $server->client at that point?
The "uninitialised value" could be any of the above.
> And the handler (PerlAccessHandler) seems work not correctly.
Does it work as a perl request handler? (PerlHandler for mp1).
Can you get any values at all out of the ServerScore instance?
Re: help about Apache::Scoreboard
Posted by Jeff Pang <pa...@earthlink.net>.
2007/12/13, Malcolm <mj...@liminalflux.net>:
>
> Just to confirm, you do have a "use Apache::Scoreboard" in there somewhere?
>
surely I used it.
right now I got these exceptions in error_log:
[Thu Dec 13 21:53:49 2007] [notice] child pid 4660 exit signal
Segmentation fault (11)
[Thu Dec 13 21:53:49 2007] [notice] child pid 14182 exit signal
Segmentation fault (11)
[Thu Dec 13 21:53:49 2007] [notice] child pid 14884 exit signal
Segmentation fault (11)
[Thu Dec 13 21:53:49 2007] [notice] child pid 14979 exit signal
Segmentation fault (11)
[Thu Dec 13 21:53:49 2007] [notice] child pid 15095 exit signal
Segmentation fault (11)
[Thu Dec 13 21:53:49 2007] [notice] child pid 15107 exit signal
Segmentation fault (11)
[Thu Dec 13 21:53:49 2007] [notice] child pid 15108 exit signal
Segmentation fault (11)
[Thu Dec 13 21:53:49 2007] [notice] child pid 15115 exit signal
Segmentation fault (11)
[Thu Dec 13 21:53:49 2007] [notice] child pid 15118 exit signal
Segmentation fault (11)
This is my full code (the key string for generating md5 is replaced
here for privacy reasons):
use strict;
use warnings;
use Socket qw(inet_aton);
use POSIX qw(strftime);
use Digest::MD5 qw(md5_hex);
use File::Basename;
use Apache::Constants qw(OK FORBIDDEN DECLINED);
use Apache::Request ();
use Apache::Scoreboard ();
use Apache qw(exit);
sub handler {
my $r = shift;
# We decline to handle subrequests: otherwise, a few lines down we
# could get into an infinite loop.
return DECLINED unless $r->is_initial_req;
#
# for ip whitelist
#
my $ip = $r->connection->remote_ip;
my $ip_int = ip2int($ip);
my @passip = $r->dir_config->get('PassAuthIPs');
my @passip_int;
for (@passip) {
if (/-/) {
my ($start,$end) = split/-/;
my $start_int = ip2int($start);
my $end_int = ip2int($end);
for (my $i=$start_int;$i<=$end_int;$i++) {
push @passip_int,$i;
}
} else {
push @passip_int, ip2int($_);
}
}
for (@passip_int) {
return OK if $ip_int == $_;
}
#
# for limit-ip-conn
#
my $ip_count = 0;
my $limit = $r->dir_config('MaxConnPerIP') || 0;
### my $host = $r->connection->remote_host;
my $image = Apache::Scoreboard->image;
for (my $parent = $image->parent; $parent; $parent = $parent->next) {
my $server = $parent->server;
use bytes;
next if ($server->status =~ /^[\._SL]$/);
### if (($ip eq $server->client) or ($host eq $server->client)) {
if ($ip eq $server->client ) {
$ip_count++;
}
}
if ($ip_count > $limit and $limit) {
$r->log_reason("Client exceeded connection limit.", $r->filename);
return FORBIDDEN;
}
#
# for anti-stolen-links
#
my $q = Apache::Request->new($r);
my $movieid = $q->param('mid');
unless (defined $movieid) {
$movieid = getmid($r->uri);
unless (defined $movieid) {
$r->log_error("[$ip FORBIDDEN] cat't get movieid");
return FORBIDDEN;
}
}
my $shareKey = $r->dir_config('ShareKey') || '';
my $key = 'the private string';
my $str = $q->param('a') || '';
if ($str eq md5_hex($key) ){
return OK;
} else {
$r->log_reason("Auth failed.", $r->filename);
return FORBIDDEN;
}
return OK;
}
sub ip2int {
my $ip = shift;
my $nl = inet_aton($ip);
die "wrong ip $!" unless defined $nl;
return unpack('N',$nl);
}
sub getmid {
my $uri = shift;
my $path = (split/\?/,$uri)[0];
my $file = basename($path);
my ($mid) = $file =~ /^(\d+)\D+/;
return $mid;
}
1;
where I'm getting wrong? please help check it.
Thanks a lot!
Re: help about Apache::Scoreboard
Posted by Malcolm <mj...@liminalflux.net>.
On Wednesday 12 December 2007 11:36:34 pm Jeff Pang wrote:
> When added these code in my handler:
>
>
> my $r = shift;
>
> # We decline to handle subrequests: otherwise, a few lines down we
> # could get into an infinite loop.
> return DECLINED unless $r->is_initial_req;
>
> #
> # for limit-ip-conn
> #
> my $ip_count = 0;
> my $limit = $r->dir_config('MaxConnPerIP') || 0;
> my $ip = $r->connection->remote_ip;
> my $host = $r->connection->remote_host;
> my $image = Apache::Scoreboard->image;
>
> for (my $parent = $image->parent; $parent; $parent = $parent->next) {
> my $server = $parent->server;
> next if ($server->status =~ /^[\._SL]$/);
> if (($ip eq $server->client) or ($host eq $server->client)) {
> $ip_count++;
> }
> }
>
> if ($ip_count > $limit and $limit) {
> $r->log_reason("Client exceeded connection limit.", $r->filename);
> return FORBIDDEN;
> }
Just to confirm, you do have a "use Apache::Scoreboard" in there somewhere?
> I got many warnings in error_log:
>
> Use of uninitialized value in string eq at /opt/apache1.3/run/DLAuth.pm
> line 42. at /opt/apache1.3/run/DLAuth.pm line 42
> DLAuth::handler('Apache=SCALAR(0x91cbe8c)') called at /dev/null
> line 0 eval {...} called at /dev/null line 0
>
> The line 42 is:
> if (($ip eq $server->client) or ($host eq $server->client)) {
What are the values of $ip, $host and $server->client at that point?
The "uninitialised value" could be any of the above.
> And the handler (PerlAccessHandler) seems work not correctly.
Does it work as a perl request handler? (PerlHandler for mp2).
Can you get any values at all out of the ServerScore instance?