diff options
author | Eric Wong <e@80x24.org> | 2023-10-06 09:46:04 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-10-06 21:06:54 +0000 |
commit | 4c4466e455fd6940700125f8c21b326564915913 (patch) | |
tree | 5f6f5a05c8ec8d41074da74bdc566926a89c86b6 /lib/PublicInbox | |
parent | aef38b546fd15f161dc0f0c2c9ec9b7b7798672a (diff) | |
download | public-inbox-4c4466e455fd6940700125f8c21b326564915913.tar.gz |
require_bsd and require_mods(':fcntl_lock') are now supported in TestCommon to make it easier to maintain than a big list of regexps. getsockopt for SO_ACCEPTFILTER seems to always succeed, even if the retrieved struct is all zeroes.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r-- | lib/PublicInbox/Daemon.pm | 4 | ||||
-rw-r--r-- | lib/PublicInbox/IPC.pm | 1 | ||||
-rw-r--r-- | lib/PublicInbox/MboxLock.pm | 10 | ||||
-rw-r--r-- | lib/PublicInbox/POP3D.pm | 4 | ||||
-rw-r--r-- | lib/PublicInbox/TestCommon.pm | 19 |
5 files changed, 29 insertions, 9 deletions
diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm index a4c99cca..520cef72 100644 --- a/lib/PublicInbox/Daemon.pm +++ b/lib/PublicInbox/Daemon.pm @@ -634,9 +634,9 @@ sub defer_accept ($$) { my $sec = unpack('i', $x); return if $sec > 0; # systemd users may set a higher value setsockopt($s, IPPROTO_TCP, $TCP_DEFER_ACCEPT, 1); - } elsif ($^O =~ /\A(?:freebsd|netbsd)\z/) { + } elsif ($^O =~ /\A(?:freebsd|netbsd|dragonfly)\z/) { my $x = getsockopt($s, SOL_SOCKET, $SO_ACCEPTFILTER); - return if defined $x; # don't change if set + return if ($x // "\0") =~ /[^\0]/s; # don't change if set my $accf_arg = pack('a16a240', $af_name, ''); setsockopt($s, SOL_SOCKET, $SO_ACCEPTFILTER, $accf_arg); } diff --git a/lib/PublicInbox/IPC.pm b/lib/PublicInbox/IPC.pm index 839281b2..068c5623 100644 --- a/lib/PublicInbox/IPC.pm +++ b/lib/PublicInbox/IPC.pm @@ -437,6 +437,7 @@ sub DESTROY { my %NPROCESSORS_ONLN = ( linux => 84, freebsd => 58, + dragonfly => 58, openbsd => 503, netbsd => 1002 ); diff --git a/lib/PublicInbox/MboxLock.pm b/lib/PublicInbox/MboxLock.pm index 95aa9862..9d7d4a32 100644 --- a/lib/PublicInbox/MboxLock.pm +++ b/lib/PublicInbox/MboxLock.pm @@ -12,9 +12,13 @@ use PublicInbox::DS qw(now); # ugh... use autodie qw(chdir opendir unlink); our $TMPL = do { - if ($^O eq 'linux') { \'s @32' } - elsif ($^O =~ /bsd/) { \'@20 s @256' } # n.b. @32 may be enough... - else { eval { require File::FcntlLock; 1 } } + if ($^O eq 'linux') { + \'s @32' + } elsif ($^O =~ /bsd/ || $^O eq 'dragonfly') { + \'@20 s @256' # n.b. @32 may be enough... + } else { + eval { require File::FcntlLock; 1 } + } }; # This order matches Debian policy on Linux systems. diff --git a/lib/PublicInbox/POP3D.pm b/lib/PublicInbox/POP3D.pm index 2a9ccfdd..38e982ee 100644 --- a/lib/PublicInbox/POP3D.pm +++ b/lib/PublicInbox/POP3D.pm @@ -15,7 +15,7 @@ use File::Temp 0.19 (); # 0.19 for ->newdir use Fcntl qw(F_SETLK F_UNLCK F_WRLCK SEEK_SET); my ($FLOCK_TMPL, @FLOCK_ORDER); # are all BSDs the same "struct flock"? tested Free+Net+Open... -if ($^O eq 'linux' || $^O =~ /bsd/) { +if ($^O =~ /\A(?:linux|dragonfly)\z/ || $^O =~ /bsd/) { require Config; my $off_t; my $sz = $Config::Config{lseeksize}; @@ -28,7 +28,7 @@ if ($^O eq 'linux' || $^O =~ /bsd/) { if ($^O eq 'linux') { $FLOCK_TMPL = "ss\@8$off_t$off_t\@32"; @FLOCK_ORDER = qw(l_type l_whence l_start l_len); - } elsif ($^O =~ /bsd/) { # @32 may be enough + } else { # *bsd including dragonfly $FLOCK_TMPL = "${off_t}${off_t}lss\@256"; @FLOCK_ORDER = qw(l_start l_len l_pid l_type l_whence); } diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm index 32213fde..323152b4 100644 --- a/lib/PublicInbox/TestCommon.pm +++ b/lib/PublicInbox/TestCommon.pm @@ -23,7 +23,7 @@ BEGIN { @EXPORT = qw(tmpdir tcp_server tcp_connect require_git require_mods run_script start_script key2sub xsys xsys_e xqx eml_load tick have_xapian_compact json_utf8 setup_public_inboxes create_inbox - create_coderepo no_scm_rights + create_coderepo require_bsd quit_waiter_pipe wait_for_eof tcp_host_port test_lei lei lei_ok $lei_out $lei_err $lei_opt test_httpd xbail require_cmd is_xdeeply tail_f @@ -35,6 +35,15 @@ BEGIN { push @EXPORT, @methods; } +sub require_bsd (;$) { + state $ok = ($^O =~ m!\A(?:free|net|open)bsd\z! || + $^O eq 'dragonfly'); + return 1 if $ok; + return if defined(wantarray); + my $m = "$0 is BSD-only (\$^O=$^O)"; + @_ ? skip($m) : plan(skip_all => $m); +} + sub xbail (@) { BAIL_OUT join(' ', map { ref() ? (explain($_)) : ($_) } @_) } sub eml_load ($) { @@ -136,7 +145,8 @@ my %IPv6_VERSION = ( sub need_accept_filter ($) { my ($af) = @_; return if $^O eq 'netbsd'; # since NetBSD 5.0 - skip 'SO_ACCEPTFILTER is FreeBSD/NetBSD-only' if $^O ne 'freebsd'; + $^O =~ /\A(?:freebsd|dragonfly)\z/ or + skip 'SO_ACCEPTFILTER is FreeBSD/NetBSD/Dragonfly-only so far'; state $tried = {}; ($tried->{$af} //= system("kldstat -m $af >/dev/null")) and skip "$af not loaded: kldload $af"; @@ -175,6 +185,11 @@ sub require_mods { push @need, $msg; next; } + } elsif ($mod eq ':fcntl_lock') { + next if $^O eq 'linux' || require_bsd; + diag "untested platform: $^O, ". + "requiring File::FcntlLock..."; + push @mods, 'File::FcntlLock'; } elsif ($mod =~ /\A\+(accf_.*)\z/) { need_accept_filter($1); next |