From: Bo Borgerson Date: Mon, 28 Apr 2008 14:30:22 +0000 (-0400) Subject: Only cleanup test dirs from the process that created them. X-Git-Tag: v6.12~83 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f55920ffc37474ac75eadfbe5d987eb0ea248cc;p=thirdparty%2Fcoreutils.git 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 --- diff --git a/tests/CuTmpdir.pm b/tests/CuTmpdir.pm index f9d2c00f02..84312a0391 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 );