diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2007-06-12 09:26:47 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2007-06-12 09:26:47 +0000 |
commit | 5d44a7a1991e292bfc38c019d99817638bc703fa (patch) | |
tree | de1c1ddf588ea44cf5e8ac37aacf89ef6b6dd0ba /usr.sbin | |
parent | 11eb6eef768bd40866428bbb50915e5da9f17677 (diff) |
tag directories and files with pid, so that we clean them up when the
corresponding process dies, not before...
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Temp.pm | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Temp.pm b/usr.sbin/pkg_add/OpenBSD/Temp.pm index f778be5583d..8dad6151564 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.10 2007/05/07 09:56:48 espie Exp $ +# $OpenBSD: Temp.pm,v 1.11 2007/06/12 09:26:46 espie Exp $ # # Copyright (c) 2003-2005 Marc Espie <espie@openbsd.org> # @@ -23,8 +23,8 @@ use File::Temp; our $tempbase = $ENV{'PKG_TMPDIR'} || '/var/tmp'; -my $dirs = []; -my $files = []; +my $dirs = {}; +my $files = {}; sub cleanup { @@ -39,8 +39,12 @@ sub cleanup local $SIG{'KILL'} = $h; local $SIG{'TERM'} = $h; - unlink(@$files); - File::Path::rmtree($dirs); + while (my ($name, $pid) = each %$files) { + unlink($name) if $pid == $$; + } + while (my ($dir, $pid) = each %$files) { + File::Path::rmtree([$dir]) if $pid == $$; + } } if (defined $caught) { kill $caught, $$; @@ -77,7 +81,7 @@ sub dir() local $SIG{'KILL'} = $h; local $SIG{'TERM'} = $h; $dir = permanent_dir($tempbase, "pkginfo"); - push(@$dirs, $dir); + $dirs->{$dir} = $$; } if (defined $caught) { kill $caught, $$; @@ -98,7 +102,7 @@ sub file() local $SIG{'KILL'} = $h; local $SIG{'TERM'} = $h; ($fh, $file) = permanent_file($tempbase, "pkgout"); - push(@$files, $file); + $files->{$file} = $$; } if (defined $caught) { kill $caught, $$; |