diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2019-07-22 06:59:42 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2019-07-22 06:59:42 +0000 |
commit | 22a942aa5a77ec59bbcf1d7dfbe80e99bf1e85ae (patch) | |
tree | f2a7b13e90d0c92c1073c2e5444f8acf40c1ada4 | |
parent | 847a27b8308a966311d514da4610c52f23b748e2 (diff) |
separate the atend behavior, because dpb wants a pure signal intercept
but not an END code.
This fixes the stupid bug I had. Was looking in the wrong location,
not surprisingly
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Error.pm | 23 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackageRepository.pm | 14 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Temp.pm | 13 |
3 files changed, 25 insertions, 25 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Error.pm b/usr.sbin/pkg_add/OpenBSD/Error.pm index d07226628cf..31b68254a96 100644 --- a/usr.sbin/pkg_add/OpenBSD/Error.pm +++ b/usr.sbin/pkg_add/OpenBSD/Error.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Error.pm,v 1.37 2019/07/21 15:31:39 espie Exp $ +# $OpenBSD: Error.pm,v 1.38 2019/07/22 06:59:41 espie Exp $ # # Copyright (c) 2004-2010 Marc Espie <espie@openbsd.org> # @@ -43,6 +43,8 @@ sub cache(*&) package OpenBSD::Handler; # hash of code to run on ANY exit +my $atend = {}; +# hash of code to run on fatal signals my $cleanup = {}; sub cleanup @@ -54,11 +56,13 @@ sub cleanup } } -#END { -# # XXX localize $? so that cleanup doesn't fuck up our exit code -# local $?; -# cleanup(); -#} +END { + # XXX localize $? so that cleanup doesn't fuck up our exit code + local $?; + for my $v (values %$atend) { + &$v(); + } +} # register each code block "by name" so that we can re-register each # block several times @@ -68,6 +72,13 @@ sub register $cleanup->{$code} = $code; } +sub atend +{ + my ($class, $code) = @_; + $cleanup->{$code} = $code; + $atend->{$code} = $code; +} + my $handler = sub { my $sig = shift; __PACKAGE__->cleanup($sig); diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm index 087b37ccb78..e84a8900826 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PackageRepository.pm,v 1.166 2019/07/17 19:00:55 sthen Exp $ +# $OpenBSD: PackageRepository.pm,v 1.167 2019/07/22 06:59:41 espie Exp $ # # Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org> # @@ -82,18 +82,12 @@ sub unique return $o; } -my $cleanup = sub { +OpenBSD::Handler->atend( + sub { for my $repo (values %$cache) { $repo->cleanup; } -}; -END { - my $a = $?; - &$cleanup; - $? = $a; -} - -OpenBSD::Handler->register($cleanup); + }); sub parse_fullurl { diff --git a/usr.sbin/pkg_add/OpenBSD/Temp.pm b/usr.sbin/pkg_add/OpenBSD/Temp.pm index 6a9096a36a4..e650e949795 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.36 2019/07/17 19:00:55 sthen Exp $ +# $OpenBSD: Temp.pm,v 1.37 2019/07/22 06:59:41 espie Exp $ # # Copyright (c) 2003-2005 Marc Espie <espie@openbsd.org> # @@ -31,21 +31,16 @@ my $files = {}; my ($lastname, $lasterror, $lasttype); -my $cleanup = sub { +OpenBSD::Handler->atend( + 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 { |