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
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/child_process.js +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -32,6 +32,16 @@ exports.fork = function(modulePath /*, args, options*/) { |
32 | 32 |
|
33 | 33 | // Prepare arguments for fork: |
34 | 34 | 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 | + |
35 | 45 | args = execArgv.concat([modulePath], args); |
36 | 46 |
|
37 | 47 | // Leave stdin open for the IPC channel. stdout and stderr should be the |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-cli-eval.js +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,6 +8,7 @@ if (module.parent) { |
8 | 8 | var common = require('../common'), |
9 | 9 | assert = require('assert'), |
10 | 10 | child = require('child_process'), |
| 11 | + path = require('path'), |
11 | 12 | nodejs = '"' + process.execPath + '"'; |
12 | 13 |
|
13 | 14 |
|
@@ -75,3 +76,11 @@ child.exec(nodejs + ' --use-strict -p process.execArgv', |
75 | 76 | function(status, stdout, stderr) { |
76 | 77 | assert.equal(stdout, "[ '--use-strict', '-p', 'process.execArgv' ]\n"); |
77 | 78 | }); |
| 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 | + }); |