From c25764aa34c5945dda48d612e20c7d323ffb782c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 4 Oct 2023 03:49:29 +0000 Subject: [PATCH] xap_helper: retry flock on EINTR While signals are currently blocked in these helpers, they may not always be... --- lib/PublicInbox/XapHelper.pm | 4 ++-- lib/PublicInbox/xap_helper.h | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/XapHelper.pm b/lib/PublicInbox/XapHelper.pm index 8c2b86d60..f90b283d9 100644 --- a/lib/PublicInbox/XapHelper.pm +++ b/lib/PublicInbox/XapHelper.pm @@ -109,9 +109,9 @@ sub dump_roots_iter ($$$) { sub dump_roots_flush ($$) { my ($req, $fh) = @_; if ($req->{wbuf} ne '') { - flock($fh, LOCK_EX) or die "flock: $!"; + until (flock($fh, LOCK_EX)) { die "LOCK_EX: $!" if !$!{EINTR} } print { $req->{0} } $req->{wbuf} or die "print: $!"; - flock($fh, LOCK_UN) or die "flock: $!"; + until (flock($fh, LOCK_UN)) { die "LOCK_UN: $!" if !$!{EINTR} } $req->{wbuf} = ''; } } diff --git a/lib/PublicInbox/xap_helper.h b/lib/PublicInbox/xap_helper.h index 5f04316c9..a78a3f769 100644 --- a/lib/PublicInbox/xap_helper.h +++ b/lib/PublicInbox/xap_helper.h @@ -441,7 +441,8 @@ static bool dump_roots_flush(struct req *req, struct dump_roots_tmp *drt) } drt->wbuf.fp = NULL; if (!drt->wbuf.len) goto done_free; - if (flock(drt->root2id_fd, LOCK_EX)) { + while (flock(drt->root2id_fd, LOCK_EX)) { + if (errno == EINTR) continue; perror("LOCK_EX"); return false; } @@ -456,7 +457,8 @@ static bool dump_roots_flush(struct req *req, struct dump_roots_tmp *drt) return false; } } while (drt->wbuf.len); - if (flock(drt->root2id_fd, LOCK_UN)) { + while (flock(drt->root2id_fd, LOCK_UN)) { + if (errno == EINTR) continue; perror("LOCK_UN"); return false; } -- 2.47.2