summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add/OpenBSD/Temp.pm
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2019-07-14 07:27:19 +0000
committerMarc Espie <espie@cvs.openbsd.org>2019-07-14 07:27:19 +0000
commit88b2c65bf15734148cde7369d43a263eb77117f1 (patch)
tree7b3483bdbc6feff3b58f429564323038506f45e9 /usr.sbin/pkg_add/OpenBSD/Temp.pm
parentb51d721eda77cb96fcc0331f9dc190d4666dcfc8 (diff)
a bunch of changes, all related to error-handling:
- have Handle->register also create a proper END block, so that individual packages don't have to, and explain the issue - kill old Unlink/Copy code that migrated to State years ago - commonalize try{} catch {} for pkg_add/delete and pkg_create, so that debug works the same way in both. - switch printing command name to the catch handler, so that exceptions are simpler to handle and a few comments for the hairy parts...
Diffstat (limited to 'usr.sbin/pkg_add/OpenBSD/Temp.pm')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Temp.pm16
1 files changed, 7 insertions, 9 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Temp.pm b/usr.sbin/pkg_add/OpenBSD/Temp.pm
index 7da540ebbd8..db695c1e158 100644
--- a/usr.sbin/pkg_add/OpenBSD/Temp.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Temp.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Temp.pm,v 1.34 2019/07/10 09:34:09 espie Exp $
+# $OpenBSD: Temp.pm,v 1.35 2019/07/14 07:27:18 espie Exp $
#
# Copyright (c) 2003-2005 Marc Espie <espie@openbsd.org>
#
@@ -26,26 +26,24 @@ use OpenBSD::Error;
our $tempbase = $ENV{'PKG_TMPDIR'} || OpenBSD::Paths->vartmp;
+# stuff that should be cleaned up on exit, registered by pid,
+# so that it gets cleaned on exit from the correct process
+
my $dirs = {};
my $files = {};
my ($lastname, $lasterror, $lasttype);
-my $cleanup = sub {
+OpenBSD::Handler->register(
+ sub {
while (my ($name, $pid) = each %$files) {
unlink($name) if $pid == $$;
}
while (my ($dir, $pid) = each %$dirs) {
OpenBSD::Error->rmtree([$dir]) if $pid == $$;
}
-};
+ });
-END {
- my $r = $?;
- &$cleanup;
- $? = $r;
-}
-OpenBSD::Handler->register($cleanup);
sub dir
{