* [PATCH 00/14] lei: another pile of changes
@ 2021-01-14 7:06 7% Eric Wong
2021-01-14 7:06 7% ` [PATCH 01/14] cmd_ipc: support + test EINTR + EAGAIN, no FDs Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-01-14 7:06 UTC (permalink / raw)
To: meta
PATCH 2/14 took forever to figure out; turns out I was hunting
an old bug in Perl :x (and led to PATCH 3/14, too)
We could probably go farther on 5/14 and eliminate the
need for @TO_CLOSE_ATFORK_CHILD completely, but my brain
was fried from 2/14 :x.
The "ts:" => "rt:" change is technically user-visible,
but "ts:" was never publicly documented so I doubt it
affects anybody. "rt:" (received time) may be documented
in the future.
Eric Wong (14):
cmd_ipc: support + test EINTR + EAGAIN, no FDs
lei: test SIGPIPE, stop xsearch workers on client abort
daemon+watch: fix localization of %SIG for non-signalfd users
lei: do not unlink socket path at exit
lei: reduce live FD references in wq child
lei: rely on localized $current_lei for warnings
lei_dedupe+shared_kv: ensure round-tripping serialization
lei q: reinstate smsg dedupe
search: rename "ts:" prefix to "rt:"
lei_overview: rename "references" to "refs"
lei: q: lock stdout on overview output
leixsearch: remove some commented out code
lei: remove temporary var on open
lei: pass FD to CWD via cmsg, use fchdir on server
MANIFEST | 2 +
lib/PublicInbox/CmdIPC4.pm | 6 +-
lib/PublicInbox/Daemon.pm | 4 +-
lib/PublicInbox/IMAPsearchqp.pm | 6 +-
lib/PublicInbox/IPC.pm | 45 +++-----
lib/PublicInbox/LEI.pm | 182 +++++++++++++++++---------------
lib/PublicInbox/LeiDedupe.pm | 29 ++---
lib/PublicInbox/LeiOverview.pm | 43 +++++++-
lib/PublicInbox/LeiQuery.pm | 27 ++---
lib/PublicInbox/LeiXSearch.pm | 60 +++++++----
lib/PublicInbox/Lock.pm | 2 +-
lib/PublicInbox/Search.pm | 2 +-
lib/PublicInbox/SharedKV.pm | 12 ++-
lib/PublicInbox/Spawn.pm | 13 ++-
script/lei | 88 +++++++++------
script/public-inbox-watch | 2 +-
t/cmd_ipc.t | 32 ++++++
t/imap_searchqp.t | 6 +-
t/lei.t | 33 +-----
t/lei_dedupe.t | 13 +++
t/lei_overview.t | 33 ++++++
xt/lei-sigpipe.t | 32 ++++++
22 files changed, 417 insertions(+), 255 deletions(-)
create mode 100644 t/lei_overview.t
create mode 100644 xt/lei-sigpipe.t
^ permalink raw reply [relevance 7%]
* [PATCH 01/14] cmd_ipc: support + test EINTR + EAGAIN, no FDs
2021-01-14 7:06 7% [PATCH 00/14] lei: another pile of changes Eric Wong
@ 2021-01-14 7:06 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-01-14 7:06 UTC (permalink / raw)
To: meta
We'll ensure our {send,recv}_cmd4 implementations are
consistent w.r.t. non-blocking and interrupted sockets.
We'll also support receiving messages without FDs associated
so we don't have to send dummy FDs to keep receivers from
reporting EOF.
---
lib/PublicInbox/CmdIPC4.pm | 6 +++---
lib/PublicInbox/Spawn.pm | 13 ++++++++-----
t/cmd_ipc.t | 32 ++++++++++++++++++++++++++++++++
3 files changed, 43 insertions(+), 8 deletions(-)
diff --git a/lib/PublicInbox/CmdIPC4.pm b/lib/PublicInbox/CmdIPC4.pm
index c4fcb0d6..c244f6a1 100644
--- a/lib/PublicInbox/CmdIPC4.pm
+++ b/lib/PublicInbox/CmdIPC4.pm
@@ -18,17 +18,17 @@ no warnings 'once';
my $mh = Socket::MsgHdr->new(buf => $_[2]);
$mh->cmsghdr(SOL_SOCKET, SCM_RIGHTS,
pack('i' x scalar(@$fds), @$fds));
- Socket::MsgHdr::sendmsg($sock, $mh, $flags) or die "sendmsg: $!";
+ Socket::MsgHdr::sendmsg($sock, $mh, $flags);
};
*recv_cmd4 = sub ($$$) {
my ($s, undef, $len) = @_; # $_[1] = destination buffer
my $mh = Socket::MsgHdr->new(buflen => $len, controllen => 256);
- my $r = Socket::MsgHdr::recvmsg($s, $mh, 0) // die "recvmsg: $!";
+ my $r = Socket::MsgHdr::recvmsg($s, $mh, 0) // return ($_[1] = undef);
$_[1] = $mh->buf;
return () if $r == 0;
my (undef, undef, $data) = $mh->cmsghdr;
- unpack('i' x (length($data) / 4), $data);
+ defined($data) ? unpack('i' x (length($data) / 4), $data) : ();
};
} } # /eval /BEGIN
diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm
index ef822e1b..e5c0b1e9 100644
--- a/lib/PublicInbox/Spawn.pm
+++ b/lib/PublicInbox/Spawn.pm
@@ -216,12 +216,13 @@ union my_cmsg {
char pad[sizeof(struct cmsghdr) + 16 + SEND_FD_SPACE];
};
-int send_cmd4(PerlIO *s, SV *svfds, SV *data, int flags)
+SV *send_cmd4(PerlIO *s, SV *svfds, SV *data, int flags)
{
struct msghdr msg = { 0 };
union my_cmsg cmsg = { 0 };
STRLEN dlen = 0;
struct iovec iov;
+ ssize_t sent;
AV *fds = (AV *)SvRV(svfds);
I32 i, nfds = av_len(fds) + 1;
int *fdp;
@@ -252,7 +253,8 @@ int send_cmd4(PerlIO *s, SV *svfds, SV *data, int flags)
*fdp++ = SvIV(*fd);
}
}
- return sendmsg(PerlIO_fileno(s), &msg, flags) >= 0;
+ sent = sendmsg(PerlIO_fileno(s), &msg, flags);
+ return sent >= 0 ? newSViv(sent) : &PL_sv_undef;
}
void recv_cmd4(PerlIO *s, SV *buf, STRLEN n)
@@ -260,7 +262,7 @@ void recv_cmd4(PerlIO *s, SV *buf, STRLEN n)
union my_cmsg cmsg = { 0 };
struct msghdr msg = { 0 };
struct iovec iov;
- size_t i;
+ ssize_t i;
Inline_Stack_Vars;
Inline_Stack_Reset;
@@ -275,8 +277,9 @@ void recv_cmd4(PerlIO *s, SV *buf, STRLEN n)
i = recvmsg(PerlIO_fileno(s), &msg, 0);
if (i < 0)
- croak("recvmsg: %s", strerror(errno));
- SvCUR_set(buf, i);
+ Inline_Stack_Push(&PL_sv_undef);
+ else
+ SvCUR_set(buf, i);
if (i > 0 && cmsg.hdr.cmsg_level == SOL_SOCKET &&
cmsg.hdr.cmsg_type == SCM_RIGHTS) {
size_t len = cmsg.hdr.cmsg_len;
diff --git a/t/cmd_ipc.t b/t/cmd_ipc.t
index 0a0a4e00..96510175 100644
--- a/t/cmd_ipc.t
+++ b/t/cmd_ipc.t
@@ -10,6 +10,7 @@ pipe(my ($r, $w)) or BAIL_OUT;
my ($send, $recv);
require_ok 'PublicInbox::Spawn';
my $SOCK_SEQPACKET = eval { Socket::SOCK_SEQPACKET() } // undef;
+use Time::HiRes qw(alarm);
my $do_test = sub { SKIP: {
my ($type, $flag, $desc) = @_;
@@ -45,11 +46,42 @@ my $do_test = sub { SKIP: {
is($buf, (',' x 1023) . '-', 'silently truncated buf');
$opens->();
$r1 = $w1 = $s1a = undef;
+
+ $s2->blocking(0);
+ @fds = $recv->($s2, $buf, length($src) + 1);
+ ok($!{EAGAIN}, "EAGAIN set by ($desc)");
+ is_deeply(\@fds, [ undef ], "EAGAIN $desc");
+ $s2->blocking(1);
+
+ my $alrm = 0;
+ local $SIG{ALRM} = sub { $alrm++ };
+ alarm(0.001);
+ @fds = $recv->($s2, $buf, length($src) + 1);
+ ok($!{EINTR}, "EINTR set by ($desc)");
+ is_deeply(\@fds, [ undef ], "EINTR $desc");
+ is($alrm, 1, 'SIGALRM hit');
+
close $s1;
@fds = $recv->($s2, $buf, length($src) + 1);
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 $!;
+ $s1->blocking(0);
+ my $nsent = 0;
+ while (defined(my $n = $send->($s1, $sfds, $src, $flag))) {
+ $nsent += $n;
+ fail "sent 0 bytes" if $n == 0;
+ }
+ ok($!{EAGAIN}, "hit EAGAIN on send $desc");
+ ok($nsent > 0, 'sent some bytes');
+
+ socketpair($s1, $s2, AF_UNIX, $type, 0) or BAIL_OUT $!;
+ is($send->($s1, [], $src, $flag), length($src), 'sent w/o FDs');
+ $buf = 'nope';
+ @fds = $recv->($s2, $buf, length($src));
+ is(scalar(@fds), 0, 'no FDs received');
+ is($buf, $src, 'recv w/o FDs');
}
} };
^ permalink raw reply related [relevance 7%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-01-14 7:06 7% [PATCH 00/14] lei: another pile of changes Eric Wong
2021-01-14 7:06 7% ` [PATCH 01/14] cmd_ipc: support + test EINTR + EAGAIN, no FDs 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).