diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2018-02-10 10:08:06 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2018-02-10 10:08:06 +0000 |
commit | cc88a7f83b313b55b8c5d75042526bd9488433e2 (patch) | |
tree | 0321845c5052cec5288e51d2390544045345d466 /usr.sbin | |
parent | 4c321531fe36a0389009bf48b54d40c73c307194 (diff) |
rewrite file around fh_file, temp file creation with signal protection,
to be used to get anon temp files for https
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Temp.pm | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Temp.pm b/usr.sbin/pkg_add/OpenBSD/Temp.pm index 76e59615044..da5b628a09c 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.27 2015/03/04 13:55:32 espie Exp $ +# $OpenBSD: Temp.pm,v 1.28 2018/02/10 10:08:05 espie Exp $ # # Copyright (c) 2003-2005 Marc Espie <espie@openbsd.org> # @@ -64,8 +64,9 @@ sub dir return "$dir/"; } -sub file +sub fh_file { + my ($stem, $cleanup) = @_; my $caught; my $h = sub { $caught = shift; }; my ($fh, $file); @@ -76,15 +77,20 @@ sub file local $SIG{'HUP'} = $h; local $SIG{'KILL'} = $h; local $SIG{'TERM'} = $h; - ($fh, $file) = permanent_file($tempbase, "pkgout"); + ($fh, $file) = permanent_file($tempbase, $stem); if (defined $file) { - $files->{$file} = $$; + &$cleanup($file); } } if (defined $caught) { kill $caught, $$; } - return $file; + return ($fh, $file); +} + +sub file +{ + return (fh_file("pkgout", sub { $files->{shift} = $$; })) [1]; } sub reclaim |