@@ -25,6 +25,7 @@ class Process extends EventEmitter
2525 private $ cwd ;
2626 private $ env ;
2727 private $ enhanceSigchildCompatibility ;
28+ private $ sigchildPipe ;
2829 private $ pipes ;
2930
3031 private $ process ;
@@ -90,10 +91,12 @@ public function start(LoopInterface $loop, $interval = 0.1)
9091 array ('pipe ' , 'w ' ), // stderr
9192 );
9293
94+ $ sigchild = null ;
9395 // Read exit code through fourth pipe to work around --enable-sigchild
9496 if ($ this ->enhanceSigchildCompatibility ) {
9597 $ fdSpec [] = array ('pipe ' , 'w ' );
96- $ cmd = sprintf ('(%s) 3>/dev/null; code=$?; echo $code >&3; exit $code ' , $ cmd );
98+ $ sigchild = 3 ;
99+ $ cmd = sprintf ('(%s) ' . $ sigchild . '>/dev/null; code=$?; echo $code >& ' . $ sigchild . '; exit $code ' , $ cmd );
97100 }
98101
99102 $ this ->process = proc_open ($ cmd , $ fdSpec , $ this ->pipes , $ this ->cwd , $ this ->env );
@@ -129,6 +132,11 @@ public function start(LoopInterface $loop, $interval = 0.1)
129132 });
130133 };
131134
135+ if ($ sigchild !== null ) {
136+ $ this ->sigchildPipe = $ this ->pipes [$ sigchild ];
137+ unset($ this ->pipes [$ sigchild ]);
138+ }
139+
132140 $ this ->stdin = new WritableResourceStream ($ this ->pipes [0 ], $ loop );
133141 $ this ->stdout = new ReadableResourceStream ($ this ->pipes [1 ], $ loop );
134142 $ this ->stdout ->on ('close ' , $ streamCloseHandler );
@@ -337,11 +345,11 @@ public final static function setSigchildEnabled($sigchild)
337345 */
338346 private function pollExitCodePipe ()
339347 {
340- if ( ! isset ( $ this ->pipes [ 3 ]) ) {
348+ if ($ this ->sigchildPipe === null ) {
341349 return ;
342350 }
343351
344- $ r = array ($ this ->pipes [ 3 ] );
352+ $ r = array ($ this ->sigchildPipe );
345353 $ w = $ e = null ;
346354
347355 $ n = @stream_select ($ r , $ w , $ e , 0 );
@@ -364,12 +372,12 @@ private function pollExitCodePipe()
364372 */
365373 private function closeExitCodePipe ()
366374 {
367- if ( ! isset ( $ this ->pipes [ 3 ]) ) {
375+ if ($ this ->sigchildPipe === null ) {
368376 return ;
369377 }
370378
371- fclose ($ this ->pipes [ 3 ] );
372- unset( $ this ->pipes [ 3 ]) ;
379+ fclose ($ this ->sigchildPipe );
380+ $ this ->sigchildPipe = null ;
373381 }
374382
375383 /**
0 commit comments