From 030a7b9c35c25d90a71f10cfde4acb6f14c2a966 Mon Sep 17 00:00:00 2001 From: espie Date: Sat, 10 Feb 2018 10:08:05 +0000 Subject: [PATCH] rewrite file around fh_file, temp file creation with signal protection, to be used to get anon temp files for https --- usr.sbin/pkg_add/OpenBSD/Temp.pm | 16 +++++++++++----- 1 file 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 # @@ -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 -- 2.20.1