diff options
author | Eric Wong <e@80x24.org> | 2023-10-06 01:02:58 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-10-06 09:38:08 +0000 |
commit | 00fe4ec336dcd8fcf3c45498d7f1ae5c228c6b92 (patch) | |
tree | 0a7d2cfe0ccd7cfd1cbc8c15017261e97ae0cb2e /lib/PublicInbox/Syscall.pm | |
parent | 14dd9df0f718f8d0815851efe52f3633ec6137b8 (diff) | |
download | public-inbox-00fe4ec336dcd8fcf3c45498d7f1ae5c228c6b92.tar.gz |
This ensures script/lei $send_cmd usage is EINTR-safe (since I prefer to avoid loading PublicInbox::IPC for startup time). Overall, it saves us some code, too.
Diffstat (limited to 'lib/PublicInbox/Syscall.pm')
-rw-r--r-- | lib/PublicInbox/Syscall.pm | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/lib/PublicInbox/Syscall.pm b/lib/PublicInbox/Syscall.pm index 4cf45d0f..e83beb6a 100644 --- a/lib/PublicInbox/Syscall.pm +++ b/lib/PublicInbox/Syscall.pm @@ -394,6 +394,8 @@ use constant msg_controllen => CMSG_SPACE(10 * SIZEOF_int) + 16; # 10 FDs if (defined($SYS_sendmsg) && defined($SYS_recvmsg)) { no warnings 'once'; +require PublicInbox::CmdIPC4; + *send_cmd4 = sub ($$$$) { my ($sock, $fds, undef, $flags) = @_; my $iov = pack('P'.TMPL_size_t, @@ -418,16 +420,12 @@ no warnings 'once'; $cmsghdr, # msg_control $msg_controllen, 0); # msg_flags - my $sent; + my $s; my $try = 0; do { - $sent = syscall($SYS_sendmsg, fileno($sock), $mh, $flags); - } while ($sent < 0 && - ($!{ENOBUFS} || $!{ENOMEM} || $!{ETOOMANYREFS}) && - (++$try < 50) && - warn "# sleeping on sendmsg: $! (#$try)\n" && - select(undef, undef, undef, 0.1) == 0); - $sent >= 0 ? $sent : undef; + $s = syscall($SYS_sendmsg, fileno($sock), $mh, $flags); + } while ($s < 0 && PublicInbox::CmdIPC4::sendmsg_retry($try)); + $s >= 0 ? $s : undef; }; *recv_cmd4 = sub ($$$) { @@ -446,8 +444,11 @@ no warnings 'once'; $cmsghdr, # msg_control msg_controllen, 0); # msg_flags - my $r = syscall($SYS_recvmsg, fileno($sock), $mh, 0); - if ($r < 0) { # $! is set + my $r; + do { + $r = syscall($SYS_recvmsg, fileno($sock), $mh, 0); + } while ($r < 0 && $!{EINTR}); + if ($r < 0) { $_[1] = ''; return (undef); } |