summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2005-10-10 10:31:47 +0000
committerMarc Espie <espie@cvs.openbsd.org>2005-10-10 10:31:47 +0000
commit891767abb6e5fc38e2b3ebf77e297b63aebc3694 (patch)
tree58751401a6bf89dd5251c49aeae44a99df261b65 /usr.sbin
parent2cdb7ee5c389c942a499d13f040e26c189aacccd (diff)
allows for tempfiles.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Temp.pm26
1 files changed, 25 insertions, 1 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Temp.pm b/usr.sbin/pkg_add/OpenBSD/Temp.pm
index e04d08823fe..8a21f069d85 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.5 2005/08/21 18:38:17 espie Exp $
+# $OpenBSD: Temp.pm,v 1.6 2005/10/10 10:31:46 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -25,10 +25,12 @@ use File::Path;
our $tempbase = $ENV{'PKG_TMPDIR'} || '/var/tmp';
my $dirs = [];
+my $files = [];
my $handler = sub {
my ($sig) = @_;
File::Path::rmtree($dirs);
+ unlink(@$files);
$SIG{$sig} = 'DEFAULT';
kill $sig, $$;
};
@@ -61,6 +63,28 @@ sub dir()
return $dir;
}
+sub file()
+{
+ my $caught;
+ my $h = sub { $caught = shift; };
+ my ($fh, $file);
+
+ {
+ local $SIG{'INT'} = $h;
+ local $SIG{'QUIT'} = $h;
+ local $SIG{'HUP'} = $h;
+ local $SIG{'KILL'} = $h;
+ local $SIG{'TERM'} = $h;
+ ($fh, $file) = File::Temp::tempfile("pkgout.XXXXXXXXXXX",
+ DIR => $tempbase, CLEANUP => 1);
+ push(@$files, $file);
+ }
+ if (defined $caught) {
+ kill $caught, $$;
+ }
+ return $file;
+}
+
sub list($)
{
return File::Temp::tempfile("list.XXXXXXXXXXX", DIR => shift);