user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/5] daemon: use per-listener SIG{__WARN__} callbacks
Date: Mon,  8 Aug 2022 23:53:08 +0000	[thread overview]
Message-ID: <20220808235311.2006279-3-e@80x24.org> (raw)
In-Reply-To: <20220808235311.2006279-1-e@80x24.org>

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 | 2 ++
 lib/PublicInbox/HTTP.pm   | 2 +-
 lib/PublicInbox/HTTPD.pm  | 1 +
 lib/PublicInbox/IMAP.pm   | 2 +-
 lib/PublicInbox/NNTP.pm   | 2 +-
 lib/PublicInbox/POP3.pm   | 1 +
 6 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm
index 0043d21e..bb140640 100644
--- a/lib/PublicInbox/Daemon.pm
+++ b/lib/PublicInbox/Daemon.pm
@@ -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;
 }
 
diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index 3d4e3499..0dba425d 100644
--- a/lib/PublicInbox/HTTP.pm
+++ b/lib/PublicInbox/HTTP.pm
@@ -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,
diff --git a/lib/PublicInbox/HTTPD.pm b/lib/PublicInbox/HTTPD.pm
index e531ee70..bae7281b 100644
--- a/lib/PublicInbox/HTTPD.pm
+++ b/lib/PublicInbox/HTTPD.pm
@@ -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},
 	}
 }
 
diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm
index 605c5e51..2be1b763 100644
--- a/lib/PublicInbox/IMAP.pm
+++ b/lib/PublicInbox/IMAP.pm
@@ -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,
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index 524784cb..ef01f448 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -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,
diff --git a/lib/PublicInbox/POP3.pm b/lib/PublicInbox/POP3.pm
index 7469922b..53fb2e05 100644
--- a/lib/PublicInbox/POP3.pm
+++ b/lib/PublicInbox/POP3.pm
@@ -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,

  parent reply	other threads:[~2022-08-08 23:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-08 23:53 [PATCH 0/5] daemon/netd-related improvements Eric Wong
2022-08-08 23:53 ` [PATCH 1/5] daemon: use default address + well-known ports for scheme Eric Wong
2022-08-08 23:53 ` Eric Wong [this message]
2022-08-08 23:53 ` [PATCH 3/5] daemon: cleanup internal data structures Eric Wong
2022-08-08 23:53 ` [PATCH 4/5] imap: mailboxes list across listeners Eric Wong
2022-08-08 23:53 ` [PATCH 5/5] imapd|nntpd: drop ->base_url preload Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220808235311.2006279-3-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).