Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
E._create_ipc_channel = fd=>{
// save process so we can restore it after _forkChild() changed it
let original_process = process;
try {
let channel = global.process = new EventEmitter();
child_process._forkChild(fd);
// fixing node bug:
// recv handle loss when msg is splitted into multiple chunks
let pipe = channel._channel, orig_onread = pipe.onread, last_handle;
pipe.onread = (nread, pool, handle)=>{
last_handle = handle||last_handle;
return orig_onread.call(pipe, nread, pool, last_handle);
};
channel.on('internalMessage', (msg, handle)=>{
if (handle===last_handle)
last_handle = null;
});
return channel;
} finally { global.process = original_process; }
};
E.create_socket_pair = ()=>etask(function*create_socket_pair(){
function setupChildProcessIpcChannel() {
if (process.env.NODE_CHANNEL_FD) {
const assert = require('internal/assert');
const fd = parseInt(process.env.NODE_CHANNEL_FD, 10);
assert(fd >= 0);
// Make sure it's not accidentally inherited by child processes.
delete process.env.NODE_CHANNEL_FD;
require('child_process')._forkChild(fd);
assert(process.send);
}
}
function setupChildProcessIpcChannel() {
if (process.env.NODE_CHANNEL_FD) {
const assert = require('internal/assert');
const fd = parseInt(process.env.NODE_CHANNEL_FD, 10);
assert(fd >= 0);
// Make sure it's not accidentally inherited by child processes.
delete process.env.NODE_CHANNEL_FD;
require('child_process')._forkChild(fd);
assert(process.send);
}
}
// start parsing data from that stream.
if (process.env.NODE_CHANNEL_FD) {
const fd = parseInt(process.env.NODE_CHANNEL_FD, 10);
assert(fd >= 0);
// Make sure it's not accidentally inherited by child processes.
delete process.env.NODE_CHANNEL_FD;
const cp = require('child_process');
// Load tcp_wrap to avoid situation where we might immediately receive
// a message.
// FIXME is this really necessary?
process.binding('tcp_wrap');
cp._forkChild(fd);
assert(process.send);
}
}