]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Only cleanup test dirs from the process that created them.
authorBo Borgerson <gigabo@gmail.com>
Mon, 28 Apr 2008 14:30:22 +0000 (10:30 -0400)
committerJim Meyering <meyering@redhat.com>
Mon, 28 Apr 2008 15:28:58 +0000 (17:28 +0200)
* tests/CuTmpdir.pm (import): Use closure around current PID to avoid cleanup races.

Signed-off-by: Bo Borgerson <gigabo@gmail.com>
tests/CuTmpdir.pm

index f9d2c00f02b52f9081c307e448b3d88a7840c6cd..84312a0391c6622e3deeba99e2bb3e6e37c64915 100644 (file)
@@ -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 );