From dd8e78633f60a4a266b870326ac87d9844dab02b Mon Sep 17 00:00:00 2001 From: Bo Borgerson Date: Mon, 28 Apr 2008 10:30:22 -0400 Subject: [PATCH] Only cleanup test dirs from the process that created them. * tests/CuTmpdir.pm (import): Use closure around current PID to avoid cleanup races. Signed-off-by: Bo Borgerson --- tests/CuTmpdir.pm | 27 ++++++++++++++------------- 1 files changed, 14 insertions(+), 13 deletions(-) diff --git a/tests/CuTmpdir.pm b/tests/CuTmpdir.pm index f9d2c00..84312a0 100644 --- a/tests/CuTmpdir.pm +++ b/tests/CuTmpdir.pm @@ -52,18 +52,6 @@ sub chmod_tree find ($options, '.'); } -sub on_sig_remove_tmpdir -{ - my ($sig) = @_; - if (defined $dir) - { - chmod_tree; - File::Temp::cleanup; - } - $SIG{$sig} = 'DEFAULT'; - kill $sig, $$; -} - sub import { my $prefix = $_[1]; @@ -82,9 +70,22 @@ sub import { or skip_test $prefix; $prefix = $1; + my $original_pid = $$; + + my $on_sig_remove_tmpdir = sub { + my ($sig) = @_; + if ($$ == $original_pid and defined $dir) + { + chmod_tree; + File::Temp::cleanup; + } + $SIG{$sig} = 'DEFAULT'; + kill $sig, $$; + }; + foreach my $sig (qw (INT TERM HUP)) { - $SIG{$sig} = \&on_sig_remove_tmpdir; + $SIG{$sig} = $on_sig_remove_tmpdir; } $dir = File::Temp::tempdir("$prefix.tmp-XXXX", CLEANUP => 1 ); -- 1.5.4.3