]> Sergey Matveev's repositories - public-inbox.git/commitdiff
daemon: use per-listener SIG{__WARN__} callbacks
authorEric Wong <e@80x24.org>
Mon, 8 Aug 2022 23:53:08 +0000 (23:53 +0000)
committerEric Wong <e@80x24.org>
Tue, 9 Aug 2022 16:41:51 +0000 (16:41 +0000)
This allows "-l $ADDRESS?err=/path/to/err.log to isolate normal
warn() (and carp()) messages for a particular listen address to
track down errors more easily.

lib/PublicInbox/Daemon.pm
lib/PublicInbox/HTTP.pm
lib/PublicInbox/HTTPD.pm
lib/PublicInbox/IMAP.pm
lib/PublicInbox/NNTP.pm
lib/PublicInbox/POP3.pm

index 0043d21eef4be44b7f391d6d1ce4099d2f091d20..bb140640c3219ec7f69b6cf9ab853039fc9fb893 100644 (file)
@@ -134,6 +134,8 @@ sub load_mod ($;$$) {
                $tlsd->{$f} = $logs{$p} //= open_log_path(my $fh, $p);
                warn "# $scheme://$addr $f=$p\n";
        }
+       my $err = $tlsd->{err};
+       $tlsd->{warn_cb} = sub { print $err @_ }; # for local $SIG{__WARN__}
        \%xn;
 }
 
index 3d4e34995dfbd9f11749c052ec7f6766331177f5..0dba425dd6354d4925fa82b49a24ea669a16db76 100644 (file)
@@ -69,7 +69,7 @@ sub new ($$$) {
 
 sub event_step { # called by PublicInbox::DS
        my ($self) = @_;
-
+       local $SIG{__WARN__} = $self->{srv_env}->{'pi-httpd.warn_cb'};
        return unless $self->flush_write && $self->{sock};
 
        # only read more requests if we've drained the write buffer,
index e531ee707e6d0a81cd85dd8eee6e31f399105c3f..bae7281b7979f92b483a0a26c5cc7f542f7f3464 100644 (file)
@@ -47,6 +47,7 @@ sub env_for ($$$) {
                # detect when to use async paths for slow blobs
                'pi-httpd.async' => \&pi_httpd_async,
                'pi-httpd.app' => $self->{app},
+               'pi-httpd.warn_cb' => $self->{warn_cb},
        }
 }
 
index 605c5e515110d1b0f1a077be70174149a78b22de..2be1b763f30a89f12e84a8c1fa0339026cf3937d 100644 (file)
@@ -1186,7 +1186,7 @@ sub out ($$;@) {
 # callback used by PublicInbox::DS for any (e)poll (in/out/hup/err)
 sub event_step {
        my ($self) = @_;
-
+       local $SIG{__WARN__} = $self->{imapd}->{warn_cb};
        return unless $self->flush_write && $self->{sock} && !$self->{long_cb};
 
        # only read more requests if we've drained the write buffer,
index 524784cb90ac3a6dfabc29f030d5e7cd32fe2704..ef01f44886203abdeaa3b07dad35226a9e7d6770 100644 (file)
@@ -958,7 +958,7 @@ sub out ($$;@) {
 # callback used by PublicInbox::DS for any (e)poll (in/out/hup/err)
 sub event_step {
        my ($self) = @_;
-
+       local $SIG{__WARN__} = $self->{nntpd}->{warn_cb};
        return unless $self->flush_write && $self->{sock} && !$self->{long_cb};
 
        # only read more requests if we've drained the write buffer,
index 7469922b2249f405be5a012eaa25e66c681087da..53fb2e05900b0b94f1a112189817fc12571ae0b6 100644 (file)
@@ -351,6 +351,7 @@ sub process_line ($$) {
 # callback used by PublicInbox::DS for any (e)poll (in/out/hup/err)
 sub event_step {
        my ($self) = @_;
+       local $SIG{__WARN__} = $self->{pop3d}->{warn_cb};
        return unless $self->flush_write && $self->{sock} && !$self->{long_cb};
 
        # only read more requests if we've drained the write buffer,