From 1b2bfa0fb31533b57938479cf271ab689e0dbfad Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 15 Feb 2023 20:03:38 +0100 Subject: [PATCH] src: allow preventing debug signal handler start --- src/env-inl.h | 4 ++++ src/env.h | 1 + src/inspector_agent.cc | 6 ++++-- src/node.h | 6 +++++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/env-inl.h b/src/env-inl.h index 0ca495bd58df6f..a3757c6f206fee 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -693,6 +693,10 @@ inline bool Environment::no_global_search_paths() const { !options_->global_search_paths; } +inline bool Environment::should_start_debug_signal_handler() const { + return (flags_ & EnvironmentFlags::kNoStartDebugSignalHandler) == 0; +} + inline bool Environment::no_browser_globals() const { // configure --no-browser-globals #ifdef NODE_NO_BROWSER_GLOBALS diff --git a/src/env.h b/src/env.h index c2eb764e740400..b0ac8d705640e2 100644 --- a/src/env.h +++ b/src/env.h @@ -772,6 +772,7 @@ class Environment : public MemoryRetainer { inline bool tracks_unmanaged_fds() const; inline bool hide_console_windows() const; inline bool no_global_search_paths() const; + inline bool should_start_debug_signal_handler() const; inline bool no_browser_globals() const; inline uint64_t thread_id() const; inline worker::Worker* worker_context() const; diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index ad193d477a5a5c..3b4aa4b4482111 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc @@ -696,8 +696,10 @@ bool Agent::Start(const std::string& path, StartIoThreadAsyncCallback)); uv_unref(reinterpret_cast(&start_io_thread_async)); start_io_thread_async.data = this; - // Ignore failure, SIGUSR1 won't work, but that should not block node start. - StartDebugSignalHandler(); + if (parent_env_->should_start_debug_signal_handler()) { + // Ignore failure, SIGUSR1 won't work, but that should not block node start. + StartDebugSignalHandler(); + } parent_env_->AddCleanupHook([](void* data) { Environment* env = static_cast(data); diff --git a/src/node.h b/src/node.h index 48477e970829c3..39b03adf25a17e 100644 --- a/src/node.h +++ b/src/node.h @@ -649,7 +649,11 @@ enum Flags : uint64_t { // This control is needed by embedders who may not want to initialize the V8 // inspector in situations where one has already been created, // e.g. Blink's in Chromium. - kNoCreateInspector = 1 << 9 + kNoCreateInspector = 1 << 9, + // Controls where or not the InspectorAgent for this Environment should + // call StartDebugSignalHandler. This control is needed by embedders who may + // not want to allow other processes to start the V8 inspector. + kNoStartDebugSignalHandler = 1 << 10 }; } // namespace EnvironmentFlags