-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
process: add execve #56496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+470
−2
Closed
process: add execve #56496
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2516,8 +2516,7 @@ if (process.getuid) { | |
} | ||
``` | ||
This function is only available on POSIX platforms (i.e. not Windows or | ||
Android). | ||
This function not available on Windows. | ||
## `process.hasUncaughtExceptionCaptureCallback()` | ||
|
@@ -3343,6 +3342,33 @@ In custom builds from non-release versions of the source tree, only the | |
`name` property may be present. The additional properties should not be | ||
relied upon to exist. | ||
## `process.execve(file[, args[, env]])` | ||
<!-- YAML | ||
added: REPLACEME | ||
--> | ||
> Stability: 1 - Experimental | ||
* `file` {string} The name or path of the executable file to run. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit... not in this PR but as a separate follow on we should likely align this with the fs module handling of paths so that |
||
* `args` {string\[]} List of string arguments. No argument can contain a null-byte (`\u0000`). | ||
* `env` {Object} Environment key-value pairs. | ||
No key or value can contain a null-byte (`\u0000`). | ||
**Default:** `process.env`. | ||
Replaces the current process with a new process. | ||
This is achieved by using the `execve` POSIX function and therefore no memory or other | ||
resources from the current process are preserved, except for the standard input, | ||
standard output and standard error file descriptor. | ||
All other resources are discarded by the system when the processes are swapped, without triggering | ||
any exit or close events and without running any cleanup handler. | ||
This function will never return, unless an error occurred. | ||
ShogunPanda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This function is only available on POSIX platforms (i.e. not Windows or Android). | ||
## `process.report` | ||
<!-- YAML | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
const { skip, isWindows } = require('../common'); | ||
const { ok } = require('assert'); | ||
const { spawnSync } = require('child_process'); | ||
const { isMainThread } = require('worker_threads'); | ||
|
||
if (!isMainThread) { | ||
skip('process.execve is not available in Workers'); | ||
} else if (isWindows) { | ||
skip('process.execve is not available in Windows'); | ||
} | ||
|
||
if (process.argv[2] === 'child') { | ||
process.execve( | ||
process.execPath + '_non_existing', | ||
[__filename, 'replaced'], | ||
{ ...process.env, EXECVE_A: 'FIRST', EXECVE_B: 'SECOND', CWD: process.cwd() } | ||
); | ||
} else { | ||
const child = spawnSync(`${process.execPath}`, [`${__filename}`, 'child']); | ||
const stderr = child.stderr.toString(); | ||
|
||
ok(stderr.includes('process.execve failed with error code ENOENT'), stderr); | ||
ok(stderr.includes('execve (node:internal/process/per_thread'), stderr); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
const { mustNotCall, skip, isWindows } = require('../common'); | ||
const { strictEqual } = require('assert'); | ||
const { isMainThread } = require('worker_threads'); | ||
|
||
if (!isMainThread) { | ||
skip('process.execve is not available in Workers'); | ||
} else if (isWindows) { | ||
skip('process.execve is not available in Windows'); | ||
} | ||
|
||
if (process.argv[2] === 'replaced') { | ||
strictEqual(process.argv[2], 'replaced'); | ||
} else { | ||
process.on('exit', mustNotCall()); | ||
process.execve(process.execPath, [process.execPath, __filename, 'replaced'], process.env); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change related to this PR? Could this land separately, and should we update the YAML history section?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was already like that but docs were not updated so I did it here.