@ -230,12 +230,16 @@ util.inherits(ChildProcess, EventEmitter);
function flushStdio ( subprocess ) {
if ( subprocess . stdio == null ) return ;
subprocess . stdio . forEach ( function ( stream , fd , stdio ) {
const stdio = subprocess . stdio ;
if ( stdio == null ) return ;
for ( var i = 0 ; i < stdio . length ; i ++ ) {
const stream = stdio [ i ] ;
if ( ! stream || ! stream . readable || stream . _ readableState . readableListening )
return ;
continue ;
stream . resume ( ) ;
} ) ;
}
}
@ -268,6 +272,7 @@ ChildProcess.prototype.spawn = function(options) {
const self = this ;
var ipc ;
var ipcFd ;
var i ;
// If no `stdio` option was given - use default
var stdio = options . stdio || 'pipe' ;
@ -302,11 +307,12 @@ ChildProcess.prototype.spawn = function(options) {
if ( err !== uv . UV_ENOENT ) return err ;
} else if ( err ) {
// Close all opened fds on error
stdio . forEach ( function ( stdio ) {
if ( stdio . type === 'pipe' ) {
stdio . handle . close ( ) ;
for ( i = 0 ; i < stdio . length ; i ++ ) {
const stream = stdio [ i ] ;
if ( stream . type === 'pipe' ) {
stream . handle . close ( ) ;
}
} ) ;
}
this . _ handle . close ( ) ;
this . _ handle = null ;
@ -315,27 +321,29 @@ ChildProcess.prototype.spawn = function(options) {
this . pid = this . _ handle . pid ;
stdio . forEach ( function ( stdio , i ) {
if ( stdio . type === 'ignore' ) return ;
for ( i = 0 ; i < stdio . length ; i ++ ) {
const stream = stdio [ i ] ;
if ( stream . type === 'ignore' ) continue ;
if ( stdio . ipc ) {
if ( stream . ipc ) {
self . _ closesNeeded ++ ;
return ;
continue ;
}
if ( stdio . handle ) {
if ( stream . handle ) {
// when i === 0 - we're dealing with stdin
// (which is the only one writable pipe)
stdio . socket = createSocket ( self . pid !== 0 ? stdio . handle : null , i > 0 ) ;
stream . socket = createSocket ( self . pid !== 0 ?
stream . handle : null , i > 0 ) ;
if ( i > 0 && self . pid !== 0 ) {
self . _ closesNeeded ++ ;
stdio . socket . on ( 'close' , function ( ) {
stream . socket . on ( 'close' , function ( ) {
maybeClose ( self ) ;
} ) ;
}
}
} ) ;
}
this . stdin = stdio . length >= 1 && stdio [ 0 ] . socket !== undefined ?
stdio [ 0 ] . socket : null ;
@ -797,11 +805,11 @@ function _validateStdio(stdio, sync) {
}
// Defaults
if ( stdio === null || stdio === undefined ) {
if ( stdio == null ) {
stdio = i < 3 ? 'pipe' : 'ignore' ;
}
if ( stdio === null || stdio === 'ignore') {
if ( stdio === 'ignore') {
acc . push ( { type : 'ignore' } ) ;
} else if ( stdio === 'pipe' || typeof stdio === 'number' && stdio < 0 ) {
var a = {
@ -888,7 +896,7 @@ function getSocketList(type, slave, key) {
function maybeClose ( subprocess ) {
subprocess . _ closesGot ++ ;
if ( subprocess . _ closesGot == subprocess . _ closesNeeded ) {
if ( subprocess . _ closesGot === subprocess . _ closesNeeded ) {
subprocess . emit ( 'close' , subprocess . exitCode , subprocess . signalCode ) ;
}
}