* [PATCH 1/5] daemon: use default address + well-known ports for scheme
2022-08-08 23:53 6% [PATCH 0/5] daemon/netd-related improvements Eric Wong
@ 2022-08-08 23:53 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2022-08-08 23:53 UTC (permalink / raw)
To: meta
This ensures the "bound $URL" diagnostic message at startup
always shows the URL scheme handled if not relying on socket
inheritance.
This also avoids duplicate/unused data structures when binding
sockets ourselves, as bound socket names can expand from short
names to longer names (e.g. "0:119" => "0.0.0.0:119").
---
lib/PublicInbox/Daemon.pm | 45 +++++++++++++++++++++------------------
1 file changed, 24 insertions(+), 21 deletions(-)
diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm
index b6f4f9ed..0043d21e 100644
--- a/lib/PublicInbox/Daemon.pm
+++ b/lib/PublicInbox/Daemon.pm
@@ -192,20 +192,23 @@ EOF
foreach my $l (@cfg_listen) {
my $orig = $l;
- my $scheme = '';
- my $port;
- if ($l =~ s!\A([^:]+)://!!) { $scheme = $1 }
+ my ($scheme, $port, $opt);
+
+ $l =~ s!\A([a-z0-9]+)://!! and $scheme = $1;
+ (!$scheme && ($default_listen // '') =~ m!\A([^:]+)://!) and
+ $scheme = $1;
if ($l =~ /\A(?:\[[^\]]+\]|[^:]+):([0-9]+)/) {
$port = $1 + 0;
- my $s = $KNOWN_TLS{$port} // $KNOWN_STARTTLS{$port};
- $scheme //= $s if defined $s;
- } elsif (index($l, '/') != 0) { # unix socket
- $port //= $SCHEME2PORT{$scheme} if $scheme;
- $port // die "no port in listen=$l\n";
+ $scheme //= $KNOWN_TLS{$port} // $KNOWN_STARTTLS{$port};
+ }
+ $scheme or die "unable to determine URL scheme of $orig\n";
+ if (!defined($port) && index($l, '/') != 0) { # unix socket
+ $port = $SCHEME2PORT{$scheme} //
+ die "no port in listen=$orig\n";
$l =~ s!\A([^/]+)!$1:$port! or
die "unable to add port=$port to $l\n";
}
- my $opt; # non-TLS options
+ $l =~ s!/\z!!; # chop one trailing slash
if ($l =~ s!/?\?(.+)\z!!) {
$opt = listener_opt($1);
$tls_opt{"$scheme://$l"} = accept_tls_opt($opt);
@@ -214,10 +217,10 @@ EOF
} elsif ($scheme =~ /\A(?:https|imaps|nntps|pop3s)\z/) {
die "$orig specified w/o cert=\n";
}
- $scheme =~ /\A(?:http|imap|nntp|pop3)/ and
+ if ($listener_names->{$l}) { # already inherited
$xnetd->{$l} = load_mod($scheme, $opt, $l);
-
- next if $listener_names->{$l}; # already inherited
+ next;
+ }
my (%o, $sock_pkg);
if (index($l, '/') == 0) {
$sock_pkg = 'IO::Socket::UNIX';
@@ -244,16 +247,16 @@ EOF
}
$o{Listen} = 1024;
my $prev = umask 0000;
- my $s = eval { $sock_pkg->new(%o) };
- warn "error binding $l: $! ($@)\n" unless $s;
+ my $s = eval { $sock_pkg->new(%o) } or
+ warn "error binding $l: $! ($@)\n";
umask $prev;
- if ($s) {
- $s->blocking(0);
- my $k = sockname($s);
- warn "# bound $scheme://$k\n";
- $listener_names->{$k} = $s;
- push @listeners, $s;
- }
+ $s // next;
+ $s->blocking(0);
+ my $sockname = sockname($s);
+ warn "# bound $scheme://$sockname\n";
+ $xnetd->{$sockname} //= load_mod($scheme);
+ $listener_names->{$sockname} = $s;
+ push @listeners, $s;
}
# cert/key options in @cfg_listen takes precedence when inheriting,
^ permalink raw reply related [relevance 7%]
* [PATCH 0/5] daemon/netd-related improvements
@ 2022-08-08 23:53 6% Eric Wong
2022-08-08 23:53 7% ` [PATCH 1/5] daemon: use default address + well-known ports for scheme Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2022-08-08 23:53 UTC (permalink / raw)
To: meta
A few minor quality-of-life improvements I've noticed while
running -netd on public-inbox.org
Eric Wong (5):
daemon: use default address + well-known ports for scheme
daemon: use per-listener SIG{__WARN__} callbacks
daemon: cleanup internal data structures
imap: mailboxes list across listeners
imapd|nntpd: drop ->base_url preload
lib/PublicInbox/Daemon.pm | 103 +++++++++++++++++++-------------------
lib/PublicInbox/HTTP.pm | 2 +-
lib/PublicInbox/HTTPD.pm | 1 +
lib/PublicInbox/IMAP.pm | 2 +-
lib/PublicInbox/IMAPD.pm | 50 +++++++++---------
lib/PublicInbox/NNTP.pm | 2 +-
lib/PublicInbox/NNTPD.pm | 1 -
lib/PublicInbox/POP3.pm | 1 +
8 files changed, 84 insertions(+), 78 deletions(-)
^ permalink raw reply [relevance 6%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2022-08-08 23:53 6% [PATCH 0/5] daemon/netd-related improvements Eric Wong
2022-08-08 23:53 7% ` [PATCH 1/5] daemon: use default address + well-known ports for scheme Eric Wong
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).