GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — child_process: don't fork bomb ourselves from -e · nodejs/node@e888471

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • child_process.js
  • test/parallel
    • test-cli-eval.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/child_process.js‎

Copy file name to clipboardExpand all lines: lib/child_process.js
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ exports.fork = function(modulePath /*, args, options*/) {
3232

3333
// Prepare arguments for fork:
3434
execArgv = options.execArgv || process.execArgv;
35+
36+
if (execArgv === process.execArgv && process._eval != null) {
37+
const index = execArgv.lastIndexOf(process._eval);
38+
if (index > 0) {
39+
// Remove the -e switch to avoid fork bombing ourselves.
40+
execArgv = execArgv.slice();
41+
execArgv.splice(index - 1, 2);
42+
}
43+
}
44+
3545
args = execArgv.concat([modulePath], args);
3646

3747
// Leave stdin open for the IPC channel. stdout and stderr should be the
Collapse file

‎test/parallel/test-cli-eval.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-cli-eval.js
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ if (module.parent) {
88
var common = require('../common'),
99
assert = require('assert'),
1010
child = require('child_process'),
11+
path = require('path'),
1112
nodejs = '"' + process.execPath + '"';
1213

1314

@@ -75,3 +76,11 @@ child.exec(nodejs + ' --use-strict -p process.execArgv',
7576
function(status, stdout, stderr) {
7677
assert.equal(stdout, "[ '--use-strict', '-p', 'process.execArgv' ]\n");
7778
});
79+
80+
// Regression test for https://github.com/nodejs/node/issues/3574
81+
const emptyFile = path.join(common.fixturesDir, 'empty.js');
82+
child.exec(nodejs + ` -e 'require("child_process").fork("${emptyFile}")'`,
83+
function(status, stdout, stderr) {
84+
assert.equal(stdout, '');
85+
assert.equal(stderr, '');
86+
});

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.