|
@ -1,5 +1,6 @@ |
|
|
'use strict'; |
|
|
'use strict'; |
|
|
|
|
|
|
|
|
|
|
|
const errors = require('internal/errors'); |
|
|
const StringDecoder = require('string_decoder').StringDecoder; |
|
|
const StringDecoder = require('string_decoder').StringDecoder; |
|
|
const EventEmitter = require('events'); |
|
|
const EventEmitter = require('events'); |
|
|
const net = require('net'); |
|
|
const net = require('net'); |
|
@ -367,6 +368,7 @@ function onErrorNT(self, err) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ChildProcess.prototype.kill = function(sig) { |
|
|
ChildProcess.prototype.kill = function(sig) { |
|
|
|
|
|
|
|
|
const signal = sig === 0 ? sig : |
|
|
const signal = sig === 0 ? sig : |
|
|
convertToValidSignal(sig === undefined ? 'SIGTERM' : sig); |
|
|
convertToValidSignal(sig === undefined ? 'SIGTERM' : sig); |
|
|
|
|
|
|
|
@ -538,7 +540,7 @@ function setupChannel(target, channel) { |
|
|
options = undefined; |
|
|
options = undefined; |
|
|
} else if (options !== undefined && |
|
|
} else if (options !== undefined && |
|
|
(options === null || typeof options !== 'object')) { |
|
|
(options === null || typeof options !== 'object')) { |
|
|
throw new TypeError('"options" argument must be an object'); |
|
|
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
options = Object.assign({swallowErrors: false}, options); |
|
|
options = Object.assign({swallowErrors: false}, options); |
|
@ -546,7 +548,7 @@ function setupChannel(target, channel) { |
|
|
if (this.connected) { |
|
|
if (this.connected) { |
|
|
return this._send(message, handle, options, callback); |
|
|
return this._send(message, handle, options, callback); |
|
|
} |
|
|
} |
|
|
const ex = new Error('channel closed'); |
|
|
const ex = new errors.Error('ERR_IPC_CHANNEL_CLOSED'); |
|
|
if (typeof callback === 'function') { |
|
|
if (typeof callback === 'function') { |
|
|
process.nextTick(callback, ex); |
|
|
process.nextTick(callback, ex); |
|
|
} else { |
|
|
} else { |
|
@ -559,7 +561,7 @@ function setupChannel(target, channel) { |
|
|
assert(this.connected || this.channel); |
|
|
assert(this.connected || this.channel); |
|
|
|
|
|
|
|
|
if (message === undefined) |
|
|
if (message === undefined) |
|
|
throw new TypeError('"message" argument cannot be undefined'); |
|
|
throw new errors.TypeError('ERR_MISSING_ARGS', 'message'); |
|
|
|
|
|
|
|
|
// Support legacy function signature
|
|
|
// Support legacy function signature
|
|
|
if (typeof options === 'boolean') { |
|
|
if (typeof options === 'boolean') { |
|
@ -586,7 +588,7 @@ function setupChannel(target, channel) { |
|
|
} else if (handle instanceof UDP) { |
|
|
} else if (handle instanceof UDP) { |
|
|
message.type = 'dgram.Native'; |
|
|
message.type = 'dgram.Native'; |
|
|
} else { |
|
|
} else { |
|
|
throw new TypeError('This handle type can\'t be sent'); |
|
|
throw new errors.TypeError('ERR_INVALID_HANDLE_TYPE'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Queue-up message and handle if we haven't received ACK yet.
|
|
|
// Queue-up message and handle if we haven't received ACK yet.
|
|
@ -686,7 +688,7 @@ function setupChannel(target, channel) { |
|
|
|
|
|
|
|
|
target.disconnect = function() { |
|
|
target.disconnect = function() { |
|
|
if (!this.connected) { |
|
|
if (!this.connected) { |
|
|
this.emit('error', new Error('IPC channel is already disconnected')); |
|
|
this.emit('error', new errors.Error('ERR_IPC_DISCONNECTED')); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -766,11 +768,12 @@ function _validateStdio(stdio, sync) { |
|
|
case 'ignore': stdio = ['ignore', 'ignore', 'ignore']; break; |
|
|
case 'ignore': stdio = ['ignore', 'ignore', 'ignore']; break; |
|
|
case 'pipe': stdio = ['pipe', 'pipe', 'pipe']; break; |
|
|
case 'pipe': stdio = ['pipe', 'pipe', 'pipe']; break; |
|
|
case 'inherit': stdio = [0, 1, 2]; break; |
|
|
case 'inherit': stdio = [0, 1, 2]; break; |
|
|
default: throw new TypeError('Incorrect value of stdio option: ' + stdio); |
|
|
default: |
|
|
|
|
|
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'stdio', stdio); |
|
|
} |
|
|
} |
|
|
} else if (!Array.isArray(stdio)) { |
|
|
} else if (!Array.isArray(stdio)) { |
|
|
throw new TypeError('Incorrect value of stdio option: ' + |
|
|
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', |
|
|
util.inspect(stdio)); |
|
|
'stdio', util.inspect(stdio)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// At least 3 stdio will be created
|
|
|
// At least 3 stdio will be created
|
|
@ -812,9 +815,9 @@ function _validateStdio(stdio, sync) { |
|
|
// Cleanup previously created pipes
|
|
|
// Cleanup previously created pipes
|
|
|
cleanup(); |
|
|
cleanup(); |
|
|
if (!sync) |
|
|
if (!sync) |
|
|
throw new Error('Child process can have only one IPC pipe'); |
|
|
throw new errors.Error('ERR_IPC_ONE_PIPE'); |
|
|
else |
|
|
else |
|
|
throw new Error('You cannot use IPC with synchronous forks'); |
|
|
throw new errors.Error('ERR_IPC_SYNC_FORK'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ipc = new Pipe(true); |
|
|
ipc = new Pipe(true); |
|
@ -849,15 +852,14 @@ function _validateStdio(stdio, sync) { |
|
|
} else if (isUint8Array(stdio) || typeof stdio === 'string') { |
|
|
} else if (isUint8Array(stdio) || typeof stdio === 'string') { |
|
|
if (!sync) { |
|
|
if (!sync) { |
|
|
cleanup(); |
|
|
cleanup(); |
|
|
throw new TypeError('Asynchronous forks do not support ' + |
|
|
throw new errors.TypeError('ERR_INVALID_SYNC_FORK_INPUT', |
|
|
'Buffer, Uint8Array or string input: ' + |
|
|
util.inspect(stdio)); |
|
|
util.inspect(stdio)); |
|
|
|
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
// Cleanup
|
|
|
// Cleanup
|
|
|
cleanup(); |
|
|
cleanup(); |
|
|
throw new TypeError('Incorrect value for stdio stream: ' + |
|
|
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'stdio', |
|
|
util.inspect(stdio)); |
|
|
util.inspect(stdio)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return acc; |
|
|
return acc; |
|
|