From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] daemon: improve warning on missing SO_ACCEPTFILTER
Date: Sat, 30 Nov 2024 22:59:05 +0000 [thread overview]
Message-ID: <20241130225905.38128-1-e@80x24.org> (raw)
I noticed tests were failing on a freshly booted FreeBSD
instance due to the accf_http module not being loaded and
triggering autodie-generated error messages from setsockopt.
Instead, give a helpful warning message for users to use
kldload(8) to load the necessary filter.
We'll also relax tests to ignore the kldload warning and fix an
overzealous use of /.*/ while we're at by using /[^\n]/ instead
to avoid filtering out subsequent lines.
---
lib/PublicInbox/Daemon.pm | 7 +++++--
lib/PublicInbox/TestCommon.pm | 19 ++++++++++++-------
t/solver_git.t | 7 ++-----
3 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm
index 8e6ddbb9..57f01d2c 100644
--- a/lib/PublicInbox/Daemon.pm
+++ b/lib/PublicInbox/Daemon.pm
@@ -658,8 +658,11 @@ sub defer_accept ($$) {
# getsockopt can EINVAL if SO_ACCEPTFILTER is unset:
my $x = getsockopt($s, SOL_SOCKET, $SO_ACCEPTFILTER);
return if ($x // '') =~ /[^\0]/s; # don't change if set
- my $accf_arg = pack('a16a240', $af_name, '');
- setsockopt $s, SOL_SOCKET, $SO_ACCEPTFILTER, $accf_arg;
+ CORE::setsockopt $s, SOL_SOCKET, $SO_ACCEPTFILTER,
+ pack('a16a240', $af_name, '') or
+ warn 'W: ', sockname($s), <<EOM;
+ SO_ACCEPTFILTER $af_name: $! (try `kldload $af_name')
+EOM
}
};
my $err = $@; # sockname() clobbers $@
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index b863ad6b..0f5b107d 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -30,7 +30,7 @@ BEGIN {
create_coderepo require_bsd kernel_version check_broken_tmpfs
quit_waiter_pipe wait_for_eof require_git_http_backend
tcp_host_port test_lei lei lei_ok $lei_out $lei_err $lei_opt
- test_httpd xbail require_cmd is_xdeeply tail_f
+ test_httpd no_httpd_errors xbail require_cmd is_xdeeply tail_f
ignore_inline_c_missing no_pollerfd no_coredump cfg_new
strace strace_inject lsof_pid oct_is);
require Test::More;
@@ -948,6 +948,16 @@ sub create_inbox ($;@) {
$ibx;
}
+sub no_httpd_errors ($;$) {
+ my ($err, $msg) = @_;
+ open my $fh, '<', $err;
+ my $e = read_all $fh;
+ $e =~ s/^Plack::Middleware::ReverseProxy missing,\n//gms and
+ $e =~ s/^URL generation for redirects[^\n]*\n//gms;
+ $e =~ s/^W: .*?try `kldload[^\n]+\n//gms;
+ is $e, '', $msg // 'no httpd errors';
+}
+
sub test_httpd ($$;$$) {
my ($env, $client, $skip, $cb) = @_;
my ($tmpdir, $for_destroy);
@@ -976,12 +986,7 @@ sub test_httpd ($$;$$) {
ua => $ua);
$cb->() if $cb;
$td->join('TERM');
- open my $fh, '<', $err;
- my $e = read_all($fh);
- if ($e =~ s/^Plack::Middleware::ReverseProxy missing,\n//gms) {
- $e =~ s/^URL generation for redirects .*\n//gms;
- }
- is($e, '', 'no errors');
+ no_httpd_errors $err;
}
};
diff --git a/t/solver_git.t b/t/solver_git.t
index cebcf47f..c45011ad 100644
--- a/t/solver_git.t
+++ b/t/solver_git.t
@@ -43,11 +43,8 @@ my $v1_0_0_tag_short = substr($v1_0_0_tag, 0, 16);
my $expect = '69df7d565d49fbaaeb0a067910f03dc22cd52bd0';
my $non_existent = 'ee5e32211bf62ab6531bdf39b84b6920d0b6775a';
my $stderr_empty = sub {
- my ($msg) = @_;
- open my $efh, '<', "$tmpdir/stderr.log";
- my @l = <$efh>;
- @l = grep(!/reverse ?proxy/i, @l);
- is_xdeeply(\@l, [], $msg // 'stderr.log is empty');
+ no_httpd_errors "$tmpdir/stderr.log",
+ $_[0] // 'stderr.log is empty';
};
test_lei({tmpdir => "$tmpdir/blob"}, sub {
reply other threads:[~2024-11-30 22:59 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20241130225905.38128-1-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.
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).