diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2005-08-21 18:38:18 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2005-08-21 18:38:18 +0000 |
commit | 7b30e5f8535eab404ba703eebc6d9997d805fef1 (patch) | |
tree | e45dc0e17e531b2dc58180991909fdb300f66507 /usr.sbin/pkg_add/OpenBSD/Temp.pm | |
parent | 6b5e78b08ac827912539aaa0bb3af6fcebad2073 (diff) |
catch QUIT, HUP, KILL, TERM along with INT, remove the temp dirs, then die.
(remember, perl signal handlers are safe, e.g., there's a redirection).
Handle critical section where we create the directory so that we die after
it's registered.
Diffstat (limited to 'usr.sbin/pkg_add/OpenBSD/Temp.pm')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Temp.pm | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Temp.pm b/usr.sbin/pkg_add/OpenBSD/Temp.pm index 741e2ea221a..e04d08823fe 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.4 2005/08/19 00:09:51 espie Exp $ +# $OpenBSD: Temp.pm,v 1.5 2005/08/21 18:38:17 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -26,17 +26,38 @@ our $tempbase = $ENV{'PKG_TMPDIR'} || '/var/tmp'; my $dirs = []; -$SIG{'INT'} = sub { +my $handler = sub { + my ($sig) = @_; File::Path::rmtree($dirs); - $SIG{'INT'} = 'DEFAULT'; - kill 'INT', $$; + $SIG{$sig} = 'DEFAULT'; + kill $sig, $$; }; +$SIG{'INT'} = $handler; +$SIG{'QUIT'} = $handler; +$SIG{'HUP'} = $handler; +$SIG{'KILL'} = $handler; +$SIG{'TERM'} = $handler; + sub dir() { - my $dir = File::Temp::tempdir("pkginfo.XXXXXXXXXXX", DIR => $tempbase, - CLEANUP => 1).'/'; - push(@$dirs, $dir); + my $caught; + my $h = sub { $caught = shift; }; + my $dir; + + { + local $SIG{'INT'} = $h; + local $SIG{'QUIT'} = $h; + local $SIG{'HUP'} = $h; + local $SIG{'KILL'} = $h; + local $SIG{'TERM'} = $h; + $dir = File::Temp::tempdir("pkginfo.XXXXXXXXXXX", + DIR => $tempbase, CLEANUP => 1).'/'; + push(@$dirs, $dir); + } + if (defined $caught) { + kill $caught, $$; + } return $dir; } |