Hi all,

Attached is the patch that prevents ccc/c++-analyzer from hang if launched with ActivePerl or Strawberry Perl interpreters. The patch replaces the code that creates a pipe from child to parent to the more portable explicit writing to parent, this prevent interpreters from hang. The conditions for hang are: child should open a pipe to the parent and parent should read from the child, otherwise no hang.

The problem is possibly caused by the bug in emulation of 'fork' by Perl interpreters on Windows. From perlfork <http://perldoc.perl.org/perlfork.html> documentation, BUGS section: "In certain cases, the OS-level handles created by the pipe(), socket(), and accept() operators are apparently not duplicated accurately in pseudo-processes. This only happens in some situations, but where it does happen, it may result in deadlocks between the read and write ends of pipe handles, or inability to send or receive data across socket handles."

An example from perlfork documentation also hangs:

# simulate open(FOO, "-|")
sub pipe_from_fork ($) {
    my $parent = shift;
    pipe $parent, my $child or die;
    my $pid = fork();
    die "fork() failed: $!" unless defined $pid;
    if ($pid) {
      close $child;
    }
    else {
      close $parent;
      open(STDOUT, ">&=" . fileno($child)) or die;
    }
  $pid;
}

if (pipe_from_fork('BAR')) {
# parent
while (<BAR>) { print; }
  close BAR;
}
else {
  # child
  print "pipe_from_fork\n";
  exit(0);
}

The hang is not reproduced only with the MSYS Perl.

OK to commit?

--
Anton

Index: ccc-analyzer
===================================================================
--- ccc-analyzer	(revision 218624)
+++ ccc-analyzer	(working copy)
@@ -154,9 +154,12 @@
   my $pid = fork();
   if ($pid == 0) {
     close FROM_CHILD;
-    open(STDOUT,">&", \*TO_PARENT);
-    open(STDERR,">&", \*TO_PARENT);
-    exec $Clang, "-###", $mode, @$Args;
+    my $ExecLine = join(' ', $Clang, "-###", $mode, @$Args, "2>&1", "|");
+    open(PS, $ExecLine);
+    while ( <PS> ) {
+      print TO_PARENT $_;
+    }
+    exit;
   }
   close(TO_PARENT);
   my $line;
@@ -255,9 +258,12 @@
   my $pid = fork();
   if ($pid == 0) {
     close FROM_CHILD;
-    open(STDOUT,">&", \*TO_PARENT);
-    open(STDERR,">&", \*TO_PARENT);
-    exec $Cmd, @CmdArgs;
+    my $ExecLine = join(' ', $Cmd, @CmdArgs, "2>&1", "|");
+    open(PS, $ExecLine);
+    while ( <PS> ) {
+      print TO_PARENT $_;
+    }
+    exit;
   }
 
   close TO_PARENT;
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to