Eliminate the creeping use of warn() in favor of log() and make

more use of the "fd:#" code everywhere.

* lib/Qpsmtpd.pm
    Default log method use '$self->fd()' instead of '$self->{fd}'.
    Include a sub fd() method for inheritance purposes.

* lib/Qpsmtpd/PollServer.pm
    Inherit log() from Qpsmtpd.pm (via SMTP.pm).

* lib/Qpsmtpd/Plugin.pm
    Appropriate code allow plugins to inherit fd().

* plugins/dnsbl
    Use log() instead of warn().

* plugins/logging/adaptive
  plugins/logging/warn
    Include the 'fd:#' to the log line if defined.

* qpsmtpd
    Reorder things slightly so we can use log().

git-svn-id: https://svn.perl.org/qpsmtpd/trunk@589 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
John Peacock 2005-12-30 17:03:14 +00:00
parent 2535e77293
commit 7cc114edd5
7 changed files with 24 additions and 20 deletions

View File

@ -76,7 +76,7 @@ sub varlog {
unless ( $rc and $rc == DECLINED or $rc == OK ) { unless ( $rc and $rc == DECLINED or $rc == OK ) {
# no logging plugins registered so fall back to STDERR # no logging plugins registered so fall back to STDERR
my $fd = $self->{fd}; my $fd = $self->fd();
warn join(" ", $$ . warn join(" ", $$ .
(defined $fd ? " fd:$fd" : "") . (defined $fd ? " fd:$fd" : "") .
(defined $plugin ? " $plugin plugin:" : (defined $plugin ? " $plugin plugin:" :
@ -370,7 +370,7 @@ sub finish_continuation {
$r[0] = DECLINED if not defined $r[0]; $r[0] = DECLINED if not defined $r[0];
my $responder = $hook . "_respond"; my $responder = $hook . "_respond";
if (my $meth = $self->can($responder)) { if (my $meth = $self->can($responder)) {
warn("continuation finished on $self\n"); $self->log(LOGNOTICE, "continuation finished on $self\n");
return $meth->($self, $r[0], $r[1], @$args); return $meth->($self, $r[0], $r[1], @$args);
} }
die "No ${hook}_respond method"; die "No ${hook}_respond method";
@ -501,6 +501,10 @@ sub auth_mechanism {
return (defined $self->{_auth_mechanism} ? $self->{_auth_mechanism} : "" ); return (defined $self->{_auth_mechanism} ? $self->{_auth_mechanism} : "" );
} }
sub fd {
return shift->{fd};
}
1; 1;
__END__ __END__

View File

@ -50,6 +50,10 @@ sub qp {
shift->{_qp}; shift->{_qp};
} }
sub fd {
shift->qp->fd();
}
sub log { sub log {
my $self = shift; my $self = shift;
$self->qp->varlog(shift, $self->hook_name, $self->plugin_name, @_) $self->qp->varlog(shift, $self->hook_name, $self->plugin_name, @_)
@ -116,7 +120,7 @@ sub isa_plugin {
$self->compile($self->plugin_name . "_isa_$cleanParent", $self->compile($self->plugin_name . "_isa_$cleanParent",
$newPackage, $newPackage,
"plugins/$parent"); # assumes Cwd is qpsmtpd root "plugins/$parent"); # assumes Cwd is qpsmtpd root
warn "---- $newPackage\n"; $self->log(LOGDEBUG,"---- $newPackage\n");
no strict 'refs'; no strict 'refs';
push @{"${currentPackage}::ISA"}, $newPackage; push @{"${currentPackage}::ISA"}, $newPackage;
} }

View File

@ -98,13 +98,6 @@ sub fault {
return; return;
} }
sub log {
my ($self, $trace, @log) = @_;
my $fd = $self->{fd};
$fd ||= '?';
$self->SUPER::log($trace, "fd:$fd", @log);
}
sub process_line { sub process_line {
my $self = shift; my $self = shift;
my $line = shift || return; my $line = shift || return;

View File

@ -75,7 +75,7 @@ sub finished {
sub process_a_result { sub process_a_result {
my ($qp, $template, $result, $query) = @_; my ($qp, $template, $result, $query) = @_;
warn("Result for A $query: $result\n"); $qp->log(LOGINFO, "Result for A $query: $result\n");
if ($result !~ /^\d+\.\d+\.\d+\.\d+$/) { if ($result !~ /^\d+\.\d+\.\d+\.\d+$/) {
# NXDOMAIN or ERROR possibly... # NXDOMAIN or ERROR possibly...
# $qp->finish_continuation if $qp->input_sock->readable; # $qp->finish_continuation if $qp->input_sock->readable;
@ -92,7 +92,7 @@ sub process_a_result {
sub process_txt_result { sub process_txt_result {
my ($qp, $result, $query) = @_; my ($qp, $result, $query) = @_;
warn("Result for TXT $query: $result\n"); $qp->log(LOGINFO, "Result for TXT $query: $result\n");
if ($result !~ /[a-z]/) { if ($result !~ /[a-z]/) {
# NXDOMAIN or ERROR probably... # NXDOMAIN or ERROR probably...
# $qp->finish_continuation if $qp->input_sock->readable; # $qp->finish_continuation if $qp->input_sock->readable;

View File

@ -44,8 +44,10 @@ sub hook_logging { # wlog
return DECLINED if defined $plugin and $plugin eq $self->plugin_name; return DECLINED if defined $plugin and $plugin eq $self->plugin_name;
if ( defined $self->{_maxlevel} && $trace <= $self->{_maxlevel} ) { if ( defined $self->{_maxlevel} && $trace <= $self->{_maxlevel} ) {
my $fd = $self->fd();
warn join( warn join(
" ", $$. " ", $$.
(defined $fd ? " fd:$fd" : "") .
( (
defined $plugin ? " $plugin plugin:" defined $plugin ? " $plugin plugin:"
: defined $hook ? " running plugin ($hook):" : defined $hook ? " running plugin ($hook):"

View File

@ -29,11 +29,13 @@ sub hook_logging {
# then these lines will not be logged at all. You can safely comment # then these lines will not be logged at all. You can safely comment
# out this line and it will not cause an infinite loop. # out this line and it will not cause an infinite loop.
return DECLINED if defined $plugin and $plugin eq $self->plugin_name; return DECLINED if defined $plugin and $plugin eq $self->plugin_name;
my $fd = $self->fd();
warn warn
join(" ", $$ . join(" ", $$ .
(defined $plugin ? " $plugin plugin:" : (defined $fd ? " fd:$fd" : "") .
defined $hook ? " running plugin ($hook):" : ""), (defined $plugin ? " $plugin plugin:" :
defined $hook ? " running plugin ($hook):" : ""),
@log), "\n" @log), "\n"
if ($trace <= $self->{_level}); if ($trace <= $self->{_level});

11
qpsmtpd
View File

@ -189,7 +189,6 @@ sub run_as_inetd {
my $out = Qpsmtpd::PollServer->new($outsock); my $out = Qpsmtpd::PollServer->new($outsock);
$out->load_plugins; $out->load_plugins;
$out->init_logger;
$out->input_sock($client); $out->input_sock($client);
$client->push_back_read("Connect\n"); $client->push_back_read("Connect\n");
# Cause poll/kevent/epoll to end quickly in first iteration # Cause poll/kevent/epoll to end quickly in first iteration
@ -241,15 +240,15 @@ sub run_as_server {
die "unable to change uid: $!\n"; die "unable to change uid: $!\n";
$> = $quid; $> = $quid;
::log(LOGINFO, 'Running as user '.
(getpwuid($>) || $>) .
', group '.
(getgrgid($)) || $)));
# Load plugins here # Load plugins here
my $plugin_loader = Qpsmtpd::SMTP->new(); my $plugin_loader = Qpsmtpd::SMTP->new();
$plugin_loader->load_plugins; $plugin_loader->load_plugins;
$plugin_loader->log(LOGINFO, 'Running as user '.
(getpwuid($>) || $>) .
', group '.
(getgrgid($)) || $)));
if ($PROCS > 1) { if ($PROCS > 1) {
$SIG{'CHLD'} = \&sig_chld; $SIG{'CHLD'} = \&sig_chld;
my @kids; my @kids;