diff options
author | Eric Wong <e@80x24.org> | 2023-09-24 20:19:20 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-09-24 23:14:20 +0000 |
commit | 1afb6f5133444bc53db047574d5142f85dfc2218 (patch) | |
tree | 3cb40ac3a069e76ee50dd90e508cb6d0431a0904 /lib/PublicInbox | |
parent | 9852f593c5e86ffad77b2558f5028fd8f13f2c21 (diff) | |
download | public-inbox-1afb6f5133444bc53db047574d5142f85dfc2218.tar.gz |
Handling this should be done at the lowest levels possible; so away from higher-level lei code.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r-- | lib/PublicInbox/CmdIPC4.pm | 5 | ||||
-rw-r--r-- | lib/PublicInbox/LEI.pm | 1 | ||||
-rw-r--r-- | lib/PublicInbox/LeiSelfSocket.pm | 1 | ||||
-rw-r--r-- | lib/PublicInbox/Spawn.pm | 8 | ||||
-rw-r--r-- | lib/PublicInbox/Syscall.pm | 5 |
5 files changed, 13 insertions, 7 deletions
diff --git a/lib/PublicInbox/CmdIPC4.pm b/lib/PublicInbox/CmdIPC4.pm index 99890244..4bc4c729 100644 --- a/lib/PublicInbox/CmdIPC4.pm +++ b/lib/PublicInbox/CmdIPC4.pm @@ -31,7 +31,10 @@ no warnings 'once'; *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) // return (undef); + my $r = Socket::MsgHdr::recvmsg($s, $mh, 0) // do { + $_[1] = ''; + return (undef); + }; $_[1] = $mh->buf; return () if $r == 0; my (undef, undef, $data) = $mh->cmsghdr; diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index 8b62def2..1ead9bf6 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -1167,7 +1167,6 @@ sub event_step { if (scalar(@fds) == 1 && !defined($fds[0])) { return if $! == EAGAIN; die "recvmsg: $!" if $! != ECONNRESET; - $buf = ''; @fds = (); # for open loop below: } for (@fds) { open my $rfh, '+<&=', $_ } diff --git a/lib/PublicInbox/LeiSelfSocket.pm b/lib/PublicInbox/LeiSelfSocket.pm index 84367266..b8745252 100644 --- a/lib/PublicInbox/LeiSelfSocket.pm +++ b/lib/PublicInbox/LeiSelfSocket.pm @@ -25,7 +25,6 @@ sub event_step { if (scalar(@fds) == 1 && !defined($fds[0])) { return if $!{EAGAIN}; die "recvmsg: $!" unless $!{ECONNRESET}; - $buf = ''; } else { # just in case open so perl can auto-close them: for (@fds) { open my $fh, '+<&=', $_ }; } diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm index ed698afc..2b84e2d5 100644 --- a/lib/PublicInbox/Spawn.pm +++ b/lib/PublicInbox/Spawn.pm @@ -259,10 +259,12 @@ void recv_cmd4(PerlIO *s, SV *buf, STRLEN n) msg.msg_controllen = CMSG_SPACE(SEND_FD_SPACE); i = recvmsg(PerlIO_fileno(s), &msg, 0); - if (i < 0) - Inline_Stack_Push(&PL_sv_undef); - else + if (i >= 0) { SvCUR_set(buf, i); + } else { + Inline_Stack_Push(&PL_sv_undef); + SvCUR_set(buf, 0); + } 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/lib/PublicInbox/Syscall.pm b/lib/PublicInbox/Syscall.pm index 0a0912fb..776fbe23 100644 --- a/lib/PublicInbox/Syscall.pm +++ b/lib/PublicInbox/Syscall.pm @@ -444,7 +444,10 @@ no warnings 'once'; msg_controllen, 0); # msg_flags my $r = syscall($SYS_recvmsg, fileno($sock), $mh, 0); - return (undef) if $r < 0; # $! set + if ($r < 0) { # $! is set + $_[1] = ''; + return (undef); + } substr($_[1], $r, length($_[1]), ''); my @ret; if ($r > 0) { |