From 2ce79787de91dda32fb7e86cde8ef22655d040b5 Mon Sep 17 00:00:00 2001 From: Paolo Insogna Date: Tue, 7 Jan 2025 07:24:20 +0100 Subject: [PATCH] process: add execve PR-URL: https://github.com/nodejs/node/pull/56496 Reviewed-By: Matteo Collina Reviewed-By: Rafael Gonzaga Reviewed-By: Bryan English Reviewed-By: James M Snell --- doc/api/diagnostics_channel.md | 9 ++ doc/api/process.md | 30 +++++- lib/internal/bootstrap/node.js | 1 + lib/internal/process/per_thread.js | 60 +++++++++++ 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 +++++ 14 files changed, 470 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/diagnostics_channel.md b/doc/api/diagnostics_channel.md index e6531cba847..85338216e60 100644 --- a/doc/api/diagnostics_channel.md +++ b/doc/api/diagnostics_channel.md @@ -1318,6 +1318,14 @@ added: v16.18.0 Emitted when a new process is created. +`execve` + +* `execPath` {string} +* `args` {string\[]} +* `env` {string\[]} + +Emitted when [`process.execve()`][] is invoked. + #### Worker Thread + +> 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` 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. + +This function is only available on POSIX platforms (i.e. not Windows or Android). + ## `process.report`