<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">It seems that fork is the only native
      perl mean for creating subprocesses. There is a number of packages
      that provide means for spawning at cpan.org, but they are not
      guarantee to be included at the users perl distribution.</div>
    <blockquote
      cite="mid:658A0B49-9795-4D6E-AA12-363D7CD99B02@apple.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      <div>Looking at this code, it's weird that we're doing this as a
        fork/exec (or not-exec) at all. Why can't we just spawn a
        sub-process?</div>
      <div><br>
      </div>
      <div>Jordan</div>
      <div><br>
      </div>
      <br>
      <div>
        <div>On Oct 21, 2014, at 6:47 , Anton Yartsev <<a
            moz-do-not-send="true" href="mailto:anton.yartsev@gmail.com">anton.yartsev@gmail.com</a>>
          wrote:</div>
        <br class="Apple-interchange-newline">
        <blockquote type="cite">
          <meta http-equiv="content-type" content="text/html;
            charset=windows-1252">
          <div bgcolor="#FFFFFF" text="#000000"> Hi all,<br>
            <br>
            Attached is the patch that prevents ccc/c++-analyzer from
            hang if launched with ActivePerl or Strawberry Perl
            interpreters.<br>
            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.<br>
            The conditions for hang are: child should open a pipe to the
            parent and parent should read from the child, otherwise no
            hang.<br>
            <br>
            The problem is possibly caused by the bug in emulation of
            'fork' by Perl interpreters on Windows. From <a
              moz-do-not-send="true"
              href="http://perldoc.perl.org/perlfork.html">perlfork</a>
            documentation, BUGS section:<br>
            "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."<br>
            <br>
            An example from perlfork documentation also hangs:<br>
            <br>
            # simulate open(FOO, "-|")<br>
            sub pipe_from_fork ($) {<br>
                my $parent = shift;<br>
                pipe $parent, my $child or die;<br>
                my $pid = fork();<br>
                die "fork() failed: $!" unless defined $pid;<br>
                if ($pid) {<br>
                  close $child;<br>
                }<br>
                else {<br>
                  close $parent;<br>
                  open(STDOUT, ">&=" . fileno($child)) or die;<br>
                }<br>
              $pid;<br>
            }<br>
            <br>
            if (pipe_from_fork('BAR')) {<br>
            # parent<br>
            while (<BAR>) { print; }<br>
              close BAR;<br>
            }<br>
            else {<br>
              # child<br>
              print "pipe_from_fork\n";<br>
              exit(0);<br>
            }<br>
            <br>
            The hang is not reproduced only with the MSYS Perl.<br>
            <br>
            OK to commit?<br>
            <pre class="moz-signature" cols="72">-- 
Anton</pre>
          </div>
          <span><ccc-analyzer_fork_open_hang.patch></span></blockquote>
      </div>
      <br>
    </blockquote>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
Anton</pre>
  </body>
</html>