Hi all,

PAR::Packer 0.977 and up kindly share segmentation faults with the user
for the following simple script (and other usages of threads):

#!/usr/bin/perl
use strict;
use warnings;
use threads;

sub start_thread {
  print "I am a thread.\n";
}

my $thread  = threads->create("start_thread");
$thread->join();
print "I am not a thread \n";

The segmentation fault happens on creating of the thread, as far as I
can tell.

I did a manual binary-search and found that the following change caused
the SEGV's to appear:

----------------------------------------------------------------------
r1890 (orig r553):  snstanton | 2007-12-06 19:53:53 +0100

Fixed a problem where a second invocation of a --clean app could end up
using the temp directory of the previous invocation while it is still being cleaned up. This primarily happens on Windows because pids are recycled quickly. The change is to rename the temp directory to a unique name before launching the background cleanup process.


For reference, the patch was to add the following lines to par.pl:

=== script/par.pl
==================================================================
--- script/par.pl       (revision 1878)
+++ script/par.pl       (revision 1890)
@@ -161,6 +161,7 @@
 END { if ($ENV{PAR_CLEAN}) {
     require File::Temp;
     require File::Basename;
+    require File::Spec;
     my $topdir = File::Basename::dirname($par_temp);
     outs(qq{Removing files in "$par_temp"});
     File::Find::finddepth(sub { ( -d ) ? rmdir : unlink }, $par_temp);
@@ -180,6 +181,21 @@
             UNLINK => 0,
         );

+        # Because the par_temp directory is going to be deleted in a
+ # background process, the parent process id may be reused before the
+        # background process completes.  To ensure that the temporary
+        # directory does not get reused while it is being deleted, try to
+        # rename it to a name that is related to the temporary script file.
+
+ my $tmpname = (File::Spec->splitpath($tmp->filename))[2]; # filename
+        $tmpname =~ s/\.[^.]*$/.dir/;
+        my $newDir = File::Spec->catpath(
+            (File::Spec->splitpath($par_temp))[0..1], $tmpname);
+        if (rename $par_temp, $newDir) {
+            outs("Renamed $par_temp to $newDir");
+            $par_temp = $newDir;
+        }
+
         if ($^O =~ m/win32/i) {
             print $tmp "


Removing them from SVN head "fixes" the problem.

Scott, do you have an idea what's going on?

Cheers,
Steffen

Reply via email to