* [PATCH 2/6] t/cmd_ipc: assume SOCK_SEQPACKET
@ 2023-09-24 20:19 4% ` Eric Wong
0 siblings, 0 replies; 3+ results
From: Eric Wong @ 2023-09-24 20:19 UTC (permalink / raw)
To: meta
We can also enable the SIGALRM test by default as we're killing
manually in a loop to ensure the signal handler eventually
fires.
Followup-to: 2a6063fbc4580315 ("ipc: assume SOCK_SEQPACKET exists")
---
t/cmd_ipc.t | 37 +++++++++++++++++--------------------
1 file changed, 17 insertions(+), 20 deletions(-)
diff --git a/t/cmd_ipc.t b/t/cmd_ipc.t
index 7edfc92f..461d2140 100644
--- a/t/cmd_ipc.t
+++ b/t/cmd_ipc.t
@@ -1,22 +1,20 @@
#!perl -w
# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
-use strict;
-use v5.10.1;
-use Test::More;
+use v5.12;
use PublicInbox::TestCommon;
-use Socket qw(AF_UNIX SOCK_STREAM);
-pipe(my ($r, $w)) or BAIL_OUT;
+use autodie;
+use Socket qw(AF_UNIX SOCK_STREAM SOCK_SEQPACKET);
+pipe(my $r, my $w);
my ($send, $recv);
require_ok 'PublicInbox::Spawn';
-my $SOCK_SEQPACKET = eval { Socket::SOCK_SEQPACKET() } // undef;
+require POSIX;
my $do_test = sub { SKIP: {
my ($type, $flag, $desc) = @_;
- defined $type or skip 'SOCK_SEQPACKET missing', 7;
my ($s1, $s2);
my $src = 'some payload' x 40;
- socketpair($s1, $s2, AF_UNIX, $type, 0) or BAIL_OUT $!;
+ socketpair($s1, $s2, AF_UNIX, $type, 0);
my $sfds = [ fileno($r), fileno($w), fileno($s1) ];
$send->($s1, $sfds, $src, $flag);
my (@fds) = $recv->($s2, my $buf, length($src) + 1);
@@ -37,7 +35,7 @@ my $do_test = sub { SKIP: {
@exp = stat $s1;
@cur = stat $s1a;
is("$exp[0]\0$exp[1]", "$cur[0]\0$cur[1]", '$s1 dev/ino matches');
- if (defined($SOCK_SEQPACKET) && $type == $SOCK_SEQPACKET) {
+ if ($type == SOCK_SEQPACKET) {
$r1 = $w1 = $s1a = undef;
$src = (',' x 1023) . '-' .('.' x 1024);
$send->($s1, $sfds, $src, $flag);
@@ -52,17 +50,16 @@ my $do_test = sub { SKIP: {
is_deeply(\@fds, [ undef ], "EAGAIN $desc");
$s2->blocking(1);
- if ($ENV{TEST_ALRM}) {
+ if ('test ALRM') {
my $alrm = 0;
local $SIG{ALRM} = sub { $alrm++ };
my $tgt = $$;
- my $pid = fork // xbail "fork: $!";
+ my $pid = fork;
if ($pid == 0) {
# need to loop since Perl signals are racy
# (the interpreter doesn't self-pipe)
- while (tick(0.01)) {
- kill 'ALRM', $tgt;
- }
+ CORE::kill('ALRM', $tgt) while (tick(0.05));
+ POSIX::_exit(1);
}
@fds = $recv->($s2, $buf, length($src) + 1);
ok($!{EINTR}, "EINTR set by ($desc)");
@@ -77,7 +74,7 @@ my $do_test = sub { SKIP: {
is_deeply(\@fds, [], "no FDs on EOF $desc");
is($buf, '', "buffer cleared on EOF ($desc)");
- socketpair($s1, $s2, AF_UNIX, $type, 0) or BAIL_OUT $!;
+ socketpair($s1, $s2, AF_UNIX, $type, 0);
$s1->blocking(0);
my $nsent = 0;
my $srclen = length($src);
@@ -90,7 +87,7 @@ my $do_test = sub { SKIP: {
or diag "send failed with: $! (nsent=$nsent)";
ok($nsent > 0, 'sent some bytes');
- socketpair($s1, $s2, AF_UNIX, $type, 0) or BAIL_OUT $!;
+ socketpair($s1, $s2, AF_UNIX, $type, 0);
is($send->($s1, [], $src, $flag), length($src), 'sent w/o FDs');
$buf = 'nope';
@fds = $recv->($s2, $buf, length($src));
@@ -123,7 +120,7 @@ SKIP: {
$send = $send_ic;
$recv = $recv_ic;
$do_test->(SOCK_STREAM, 0, 'Inline::C stream');
- $do_test->($SOCK_SEQPACKET, 0, 'Inline::C seqpacket');
+ $do_test->(SOCK_SEQPACKET, 0, 'Inline::C seqpacket');
}
SKIP: {
@@ -132,13 +129,13 @@ SKIP: {
$send = PublicInbox::CmdIPC4->can('send_cmd4');
$recv = PublicInbox::CmdIPC4->can('recv_cmd4');
$do_test->(SOCK_STREAM, 0, 'MsgHdr stream');
- $do_test->($SOCK_SEQPACKET, 0, 'MsgHdr seqpacket');
+ $do_test->(SOCK_SEQPACKET, 0, 'MsgHdr seqpacket');
SKIP: {
($send_ic && $recv_ic) or
skip 'Inline::C not installed/enabled', 12;
$recv = $recv_ic;
$do_test->(SOCK_STREAM, 0, 'Inline::C -> MsgHdr stream');
- $do_test->($SOCK_SEQPACKET, 0, 'Inline::C -> MsgHdr seqpacket');
+ $do_test->(SOCK_SEQPACKET, 0, 'Inline::C -> MsgHdr seqpacket');
}
}
@@ -150,7 +147,7 @@ SKIP: {
$recv = PublicInbox::Syscall->can('recv_cmd4') or
skip 'recv_cmd4 not defined for arch';
$do_test->(SOCK_STREAM, 0, 'PP Linux stream');
- $do_test->($SOCK_SEQPACKET, 0, 'PP Linux seqpacket');
+ $do_test->(SOCK_SEQPACKET, 0, 'PP Linux seqpacket');
}
done_testing;
^ permalink raw reply related [relevance 4%]
* [PATCH 3/8] ipc: assume SOCK_SEQPACKET exists
2023-09-18 10:15 5% [PATCH 0/8] portability odds and ends Eric Wong
@ 2023-09-18 10:15 7% ` Eric Wong
0 siblings, 0 replies; 3+ results
From: Eric Wong @ 2023-09-18 10:15 UTC (permalink / raw)
To: meta
The rest of our code does, and we haven't encountered a platform
we'd care about without it.
---
lib/PublicInbox/IPC.pm | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/lib/PublicInbox/IPC.pm b/lib/PublicInbox/IPC.pm
index fa084795..9388befd 100644
--- a/lib/PublicInbox/IPC.pm
+++ b/lib/PublicInbox/IPC.pm
@@ -16,9 +16,8 @@ use PublicInbox::DS qw(awaitpid);
use PublicInbox::Spawn;
use PublicInbox::OnDestroy;
use PublicInbox::WQWorker;
-use Socket qw(AF_UNIX SOCK_STREAM);
+use Socket qw(AF_UNIX SOCK_STREAM SOCK_SEQPACKET);
my $MY_MAX_ARG_STRLEN = 4096 * 33; # extra 4K for serialization
-my $SEQPACKET = eval { Socket::SOCK_SEQPACKET() }; # portable enough?
our @EXPORT_OK = qw(ipc_freeze ipc_thaw nproc_shards);
my ($enc, $dec);
# ->imports at BEGIN turns sereal_*_with_object into custom ops on 5.14+
@@ -374,7 +373,7 @@ sub wq_nonblock_do { # always async
sub _wq_worker_start {
my ($self, $oldset, $fields, $one, @cb_args) = @_;
my ($bcast1, $bcast2);
- $one or socketpair($bcast1, $bcast2, AF_UNIX, $SEQPACKET, 0) or
+ $one or socketpair($bcast1, $bcast2, AF_UNIX, SOCK_SEQPACKET, 0) or
die "socketpair: $!";
my $seed = rand(0xffffffff);
my $pid = fork // die "fork: $!";
@@ -409,11 +408,11 @@ sub _wq_worker_start {
# starts workqueue workers if Sereal or Storable is installed
sub wq_workers_start {
my ($self, $ident, $nr_workers, $oldset, $fields, @cb_args) = @_;
- ($send_cmd && $recv_cmd && defined($SEQPACKET)) or return;
+ ($send_cmd && $recv_cmd) or return;
return if $self->{-wq_s1}; # idempotent
$self->{-wq_s1} = $self->{-wq_s2} = undef;
- socketpair($self->{-wq_s1}, $self->{-wq_s2}, AF_UNIX, $SEQPACKET, 0) or
- die "socketpair: $!";
+ socketpair($self->{-wq_s1}, $self->{-wq_s2}, AF_UNIX, SOCK_SEQPACKET, 0)
+ or die "socketpair: $!";
$self->ipc_atfork_prepare;
$nr_workers //= $self->{-wq_nr_workers}; # was set earlier
my $sigset = $oldset // PublicInbox::DS::block_signals();
^ permalink raw reply related [relevance 7%]
* [PATCH 0/8] portability odds and ends
@ 2023-09-18 10:15 5% Eric Wong
2023-09-18 10:15 7% ` [PATCH 3/8] ipc: assume SOCK_SEQPACKET exists Eric Wong
0 siblings, 1 reply; 3+ results
From: Eric Wong @ 2023-09-18 10:15 UTC (permalink / raw)
To: meta
Nothing major, just a few things I noticed while working
on various *BSDs.
Eric Wong (8):
ci/run: favor `make check' as the default target
drop GNU nproc(1) support in favor of getconf(1)
ipc: assume SOCK_SEQPACKET exists
rename t/run.perl to xt/check-run
makefile: avoid needless use of double-colon rules
pop3d: split @FLOCK into $FLOCK_TMPL and @FLOCK_ORDER
install/deps: more fixes
makefile: avoid non-POSIX which(1)
Documentation/include.mk | 10 ++++++----
MANIFEST | 2 +-
Makefile.PL | 31 +++++++++++++++++--------------
ci/run.sh | 5 +++--
install/deps.perl | 17 ++++++++++++-----
lib/PublicInbox/IPC.pm | 22 +++++++++-------------
lib/PublicInbox/POP3D.pm | 16 ++++++++--------
t/nntpd.t | 2 +-
t/run.perl => xt/check-run.t | 4 ++--
9 files changed, 59 insertions(+), 50 deletions(-)
rename t/run.perl => xt/check-run.t (98%)
^ permalink raw reply [relevance 5%]
Results 1-3 of 3 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2023-09-18 10:15 5% [PATCH 0/8] portability odds and ends Eric Wong
2023-09-18 10:15 7% ` [PATCH 3/8] ipc: assume SOCK_SEQPACKET exists Eric Wong
2023-09-24 20:19 [PATCH 0/6] various test and syscall-related fixes Eric Wong
2023-09-24 20:19 4% ` [PATCH 2/6] t/cmd_ipc: assume SOCK_SEQPACKET 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).