From 16674d0fc146f8b2685cc6e25e8b46619e5654b1 Mon Sep 17 00:00:00 2001 From: Paolo Insogna Date: Tue, 7 Jan 2025 07:24:20 +0100 Subject: [PATCH 1/4] process: add execve --- doc/api/process.md | 30 +++++- lib/internal/bootstrap/node.js | 1 + lib/internal/process/per_thread.js | 50 ++++++++++ src/node_errors.h | 5 + src/node_process_methods.cc | 99 +++++++++++++++++++ test/parallel/test-process-execve-abort.js | 26 +++++ test/parallel/test-process-execve-on-exit.js | 18 ++++ .../test-process-execve-permission-fail.js | 21 ++++ .../test-process-execve-permission-granted.js | 19 ++++ test/parallel/test-process-execve-socket.js | 49 +++++++++ .../test-process-execve-validation.js | 87 ++++++++++++++++ .../test-process-execve-worker-threads.js | 21 ++++ test/parallel/test-process-execve.js | 27 +++++ 13 files changed, 451 insertions(+), 2 deletions(-) create mode 100644 test/parallel/test-process-execve-abort.js create mode 100644 test/parallel/test-process-execve-on-exit.js create mode 100644 test/parallel/test-process-execve-permission-fail.js create mode 100644 test/parallel/test-process-execve-permission-granted.js create mode 100644 test/parallel/test-process-execve-socket.js create mode 100644 test/parallel/test-process-execve-validation.js create mode 100644 test/parallel/test-process-execve-worker-threads.js create mode 100644 test/parallel/test-process-execve.js diff --git a/doc/api/process.md b/doc/api/process.md index 874712fb612d19..552f1909ea6b4a 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -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]])\` + + + +> Stability: 1 - Experimental + +* `file` {string} The name or path of the executable file to run. +* `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` Unix 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. + +This function is only available on POSIX platforms (i.e. not Windows or Android). + ## `process.report`