diff --git a/lib/Qpsmtpd.pm b/lib/Qpsmtpd.pm index a47c4c6..025a761 100644 --- a/lib/Qpsmtpd.pm +++ b/lib/Qpsmtpd.pm @@ -76,7 +76,7 @@ sub varlog { unless ( $rc and $rc == DECLINED or $rc == OK ) { # no logging plugins registered so fall back to STDERR - my $fd = $self->{fd}; + my $fd = $self->fd(); warn join(" ", $$ . (defined $fd ? " fd:$fd" : "") . (defined $plugin ? " $plugin plugin:" : @@ -370,7 +370,7 @@ sub finish_continuation { $r[0] = DECLINED if not defined $r[0]; my $responder = $hook . "_respond"; 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); } die "No ${hook}_respond method"; @@ -501,6 +501,10 @@ sub auth_mechanism { return (defined $self->{_auth_mechanism} ? $self->{_auth_mechanism} : "" ); } +sub fd { + return shift->{fd}; +} + 1; __END__ diff --git a/lib/Qpsmtpd/Plugin.pm b/lib/Qpsmtpd/Plugin.pm index 73493b7..19e9296 100644 --- a/lib/Qpsmtpd/Plugin.pm +++ b/lib/Qpsmtpd/Plugin.pm @@ -50,6 +50,10 @@ sub qp { shift->{_qp}; } +sub fd { + shift->qp->fd(); +} + sub log { my $self = shift; $self->qp->varlog(shift, $self->hook_name, $self->plugin_name, @_) @@ -116,7 +120,7 @@ sub isa_plugin { $self->compile($self->plugin_name . "_isa_$cleanParent", $newPackage, "plugins/$parent"); # assumes Cwd is qpsmtpd root - warn "---- $newPackage\n"; + $self->log(LOGDEBUG,"---- $newPackage\n"); no strict 'refs'; push @{"${currentPackage}::ISA"}, $newPackage; } diff --git a/lib/Qpsmtpd/PollServer.pm b/lib/Qpsmtpd/PollServer.pm index 2753663..266f0f1 100644 --- a/lib/Qpsmtpd/PollServer.pm +++ b/lib/Qpsmtpd/PollServer.pm @@ -98,13 +98,6 @@ sub fault { return; } -sub log { - my ($self, $trace, @log) = @_; - my $fd = $self->{fd}; - $fd ||= '?'; - $self->SUPER::log($trace, "fd:$fd", @log); -} - sub process_line { my $self = shift; my $line = shift || return; diff --git a/plugins/dnsbl b/plugins/dnsbl index 5a9a274..cc3ff00 100644 --- a/plugins/dnsbl +++ b/plugins/dnsbl @@ -75,7 +75,7 @@ sub finished { sub process_a_result { 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+$/) { # NXDOMAIN or ERROR possibly... # $qp->finish_continuation if $qp->input_sock->readable; @@ -92,7 +92,7 @@ sub process_a_result { sub process_txt_result { my ($qp, $result, $query) = @_; - warn("Result for TXT $query: $result\n"); + $qp->log(LOGINFO, "Result for TXT $query: $result\n"); if ($result !~ /[a-z]/) { # NXDOMAIN or ERROR probably... # $qp->finish_continuation if $qp->input_sock->readable; diff --git a/plugins/logging/adaptive b/plugins/logging/adaptive index 27d0eba..934a4e6 100644 --- a/plugins/logging/adaptive +++ b/plugins/logging/adaptive @@ -44,8 +44,10 @@ sub hook_logging { # wlog return DECLINED if defined $plugin and $plugin eq $self->plugin_name; if ( defined $self->{_maxlevel} && $trace <= $self->{_maxlevel} ) { + my $fd = $self->fd(); warn join( " ", $$. + (defined $fd ? " fd:$fd" : "") . ( defined $plugin ? " $plugin plugin:" : defined $hook ? " running plugin ($hook):" diff --git a/plugins/logging/warn b/plugins/logging/warn index ce25399..ddbf351 100644 --- a/plugins/logging/warn +++ b/plugins/logging/warn @@ -29,11 +29,13 @@ sub hook_logging { # then these lines will not be logged at all. You can safely comment # out this line and it will not cause an infinite loop. return DECLINED if defined $plugin and $plugin eq $self->plugin_name; + my $fd = $self->fd(); warn join(" ", $$ . - (defined $plugin ? " $plugin plugin:" : - defined $hook ? " running plugin ($hook):" : ""), + (defined $fd ? " fd:$fd" : "") . + (defined $plugin ? " $plugin plugin:" : + defined $hook ? " running plugin ($hook):" : ""), @log), "\n" if ($trace <= $self->{_level}); diff --git a/qpsmtpd b/qpsmtpd index 3a1fd34..24b5bfa 100755 --- a/qpsmtpd +++ b/qpsmtpd @@ -189,7 +189,6 @@ sub run_as_inetd { my $out = Qpsmtpd::PollServer->new($outsock); $out->load_plugins; - $out->init_logger; $out->input_sock($client); $client->push_back_read("Connect\n"); # Cause poll/kevent/epoll to end quickly in first iteration @@ -241,15 +240,15 @@ sub run_as_server { die "unable to change uid: $!\n"; $> = $quid; - ::log(LOGINFO, 'Running as user '. - (getpwuid($>) || $>) . - ', group '. - (getgrgid($)) || $))); - # Load plugins here my $plugin_loader = Qpsmtpd::SMTP->new(); $plugin_loader->load_plugins; + $plugin_loader->log(LOGINFO, 'Running as user '. + (getpwuid($>) || $>) . + ', group '. + (getgrgid($)) || $))); + if ($PROCS > 1) { $SIG{'CHLD'} = \&sig_chld; my @kids;