about summary refs log tree commit homepage
path: root/lib/PublicInbox/MboxLock.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2024-04-01 06:49:37 +0000
committerEric Wong <e@80x24.org>2024-04-03 08:28:05 +0000
commit108196adad5e70b6dd40dc431cd1033d44679483 (patch)
tree6c9f2761263a5f188ef47d58b5c652a8f7ab2497 /lib/PublicInbox/MboxLock.pm
parent9aba037ad27f1ec8e9c37580d23ea7a8944e8ae5 (diff)
downloadpublic-inbox-108196adad5e70b6dd40dc431cd1033d44679483.tar.gz
getpid() isn't cached by glibc nowadays and system calls are
more expensive due to CPU vulnerability mitigations.  To
ensure we switch to the new semantics properly, introduce
a new `on_destroy' function to simplify callers.
Furthermore, most OnDestroy correctness is often tied to the
process which creates it, so make the new API default to
guarded against running in subprocesses.

For cases which require running in all children, a new
PublicInbox::OnDestroy::all call is provided.
Diffstat (limited to 'lib/PublicInbox/MboxLock.pm')
-rw-r--r--lib/PublicInbox/MboxLock.pm6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/PublicInbox/MboxLock.pm b/lib/PublicInbox/MboxLock.pm
index 9d7d4a32..5e373873 100644
--- a/lib/PublicInbox/MboxLock.pm
+++ b/lib/PublicInbox/MboxLock.pm
@@ -4,7 +4,7 @@
 # Various mbox locking methods
 package PublicInbox::MboxLock;
 use v5.12;
-use PublicInbox::OnDestroy;
+use PublicInbox::OnDestroy ();
 use Fcntl qw(:flock F_SETLK F_SETLKW F_RDLCK F_WRLCK
                         O_CREAT O_EXCL O_WRONLY SEEK_SET);
 use Carp qw(croak);
@@ -122,10 +122,10 @@ sub acq {
 sub DESTROY {
         my ($self) = @_;
         my $f = $self->{".lock$$"} or return;
-        my $x;
+        my $od;
         if (my $dh = delete $self->{dh}) {
                 opendir my $c, '.';
-                $x = PublicInbox::OnDestroy->new(\&chdir, $c);
+                $od = PublicInbox::OnDestroy::all \&chdir, $c;
                 chdir($dh);
         }
         CORE::unlink($f) or die "unlink($f): $! (lock stolen?)";