Fix race condition in PipeStream.
authorStefan Vogel <sv@exept.de>
Fri, 26 Jan 2007 14:17:00 +0100
changeset 10363 5cf689c14989
parent 10362 ed621d39a311
child 10364 43968474508b
Fix race condition in PipeStream. This race could falsly report io errors when forking subprocesses.
PipeStream.st
--- a/PipeStream.st	Wed Jan 24 19:55:33 2007 +0100
+++ b/PipeStream.st	Fri Jan 26 14:17:00 2007 +0100
@@ -566,7 +566,7 @@
 
     |blocked pipeFdArray execFdArray execFd myFd shellAndArgs
      shellPath shellArgs mbx mbxName 
-     realCmd execDirectory tmpComFile nullOutput|
+     realCmd execDirectory tmpComFile nullOutput resultPid|
 
     filePointer notNil ifTrue:[
         "the pipe was already open ...
@@ -665,7 +665,8 @@
 
     blocked := OperatingSystem blockInterrupts.
 
-    pid := Processor 
+    "beware: pid may change if subprocess is fast"
+    pid := resultPid :=  Processor 
                monitor:[
                   OperatingSystem 
                       exec:shellPath
@@ -705,7 +706,7 @@
         nullOutput close
     ].
 
-    pid notNil ifTrue:[
+    resultPid notNil ifTrue:[
         "successfull creation of subprocesss"
         OperatingSystem isVMSlike ifTrue:[
             "/
@@ -734,7 +735,7 @@
         OperatingSystem unblockInterrupts
     ].
 
-    (pid isNil or:[lastErrorNumber notNil]) ifTrue:[
+    (resultPid isNil or:[lastErrorNumber notNil]) ifTrue:[
         "
          the pipe open failed for some reason ...
          ... this may be either due to an invalid command string,
@@ -788,7 +789,7 @@
 !PipeStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/PipeStream.st,v 1.105 2007-01-19 13:50:01 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/PipeStream.st,v 1.106 2007-01-26 13:17:00 stefan Exp $'
 ! !
 
 PipeStream initialize!