diff options
Diffstat (limited to 'usr.sbin/pkg_add/OpenBSD/Temp.pm')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Temp.pm | 46 |
1 files changed, 10 insertions, 36 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Temp.pm b/usr.sbin/pkg_add/OpenBSD/Temp.pm index 796da4f194c..860b48431b2 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.15 2009/11/10 11:36:56 espie Exp $ +# $OpenBSD: Temp.pm,v 1.16 2010/01/09 14:49:53 espie Exp $ # # Copyright (c) 2003-2005 Marc Espie <espie@openbsd.org> # @@ -28,47 +28,21 @@ our $tempbase = $ENV{'PKG_TMPDIR'} || OpenBSD::Paths->vartmp; my $dirs = {}; my $files = {}; -sub cleanup -{ - my $caught; - my $h = sub { $caught = shift; }; - { - require File::Path; +my $cleanup = sub { + require File::Path; - local $SIG{'INT'} = $h; - local $SIG{'QUIT'} = $h; - local $SIG{'HUP'} = $h; - local $SIG{'KILL'} = $h; - local $SIG{'TERM'} = $h; - - while (my ($name, $pid) = each %$files) { - unlink($name) if $pid == $$; - } - while (my ($dir, $pid) = each %$dirs) { - File::Path::rmtree([$dir]) if $pid == $$; - } + while (my ($name, $pid) = each %$files) { + unlink($name) if $pid == $$; } - if (defined $caught) { - kill $caught, $$; + while (my ($dir, $pid) = each %$dirs) { + File::Path::rmtree([$dir]) if $pid == $$; } -} +}; END { - cleanup(); + &$cleanup; } - -my $handler = sub { - my ($sig) = @_; - cleanup(); - $SIG{$sig} = 'DEFAULT'; - kill $sig, $$; -}; - -$SIG{'INT'} = $handler; -$SIG{'QUIT'} = $handler; -$SIG{'HUP'} = $handler; -$SIG{'KILL'} = $handler; -$SIG{'TERM'} = $handler; +OpenBSD::Handler->register($cleanup); sub dir { |