X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=script%2Fpublic-inbox-init;h=6a867a22944d93e4b4d39cf49ced3f8b7e91f03a;hb=af0b0fb7a454470a32c452119d0392e0dedb3fe1;hp=85d14377c2c7aab7c8500ca79cd86fe0ab802eab;hpb=9c7737d056f832824812086373a13922dd08a0c5;p=public-inbox.git
diff --git a/script/public-inbox-init b/script/public-inbox-init
index 85d14377..6a867a22 100755
--- a/script/public-inbox-init
+++ b/script/public-inbox-init
@@ -1,5 +1,5 @@
#!perl -w
-# Copyright (C) 2014-2020 all contributors
+# Copyright (C) 2014-2021 all contributors
# License: AGPL-3.0+
use strict;
use v5.10.1;
@@ -91,7 +91,8 @@ sysopen($lockfh, $lockfile, O_RDWR|O_CREAT|O_EXCL) or do {
warn "could not open config file: $lockfile: $!\n";
exit(255);
};
-my $auto_unlink = UnlinkMe->new($lockfile);
+require PublicInbox::OnDestroy;
+my $auto_unlink = PublicInbox::OnDestroy->new($$, sub { unlink $lockfile });
my ($perm, %seen);
if (-e $pi_config) {
open(my $oh, '<', $pi_config) or die "unable to read $pi_config: $!\n";
@@ -208,18 +209,4 @@ if (defined $perm) {
rename $pi_config_tmp, $pi_config or
die "failed to rename `$pi_config_tmp' to `$pi_config': $!\n";
-$auto_unlink->DESTROY;
-
-package UnlinkMe;
-use strict;
-
-sub new {
- my ($klass, $file) = @_;
- bless { file => $file }, $klass;
-}
-
-sub DESTROY {
- my $f = delete($_[0]->{file});
- unlink($f) if defined($f);
-}
-1;
+undef $auto_unlink; # trigger ->DESTROY