diff options
author | 2007-06-12 09:26:46 +0000 | |
---|---|---|
committer | 2007-06-12 09:26:46 +0000 | |
commit | 6fe0bf6105f91c2d8bfa43182654e29a76202b8b (patch) | |
tree | fd054fd44d49e2a868497438227c6fa8608396c7 | |
parent | make scp try to skip FIFOs rather than blocking when nothing is listening. (diff) | |
download | wireguard-openbsd-6fe0bf6105f91c2d8bfa43182654e29a76202b8b.tar.xz wireguard-openbsd-6fe0bf6105f91c2d8bfa43182654e29a76202b8b.zip |
tag directories and files with pid, so that we clean them up when the
corresponding process dies, not before...
-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, $$; |