summaryrefslogtreecommitdiff
path: root/lib/internal/bootstrap/pre_execution.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/internal/bootstrap/pre_execution.js')
-rw-r--r--lib/internal/bootstrap/pre_execution.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js
index 556c6ba39e..57f7420d6c 100644
--- a/lib/internal/bootstrap/pre_execution.js
+++ b/lib/internal/bootstrap/pre_execution.js
@@ -8,6 +8,9 @@ let traceEventsAsyncHook;
function prepareMainThreadExecution() {
setupTraceCategoryState();
+ // Only main thread receives signals.
+ setupSignalHandlers();
+
// If the process is spawned with env NODE_CHANNEL_FD, it's probably
// spawned by our child_process module, then initialize IPC.
// This attaches some internal event listeners and creates:
@@ -28,6 +31,28 @@ function prepareMainThreadExecution() {
loadPreloadModules();
}
+function setupSignalHandlers() {
+ const {
+ createSignalHandlers
+ } = require('internal/process/main_thread_only');
+ const {
+ startListeningIfSignal,
+ stopListeningIfSignal
+ } = createSignalHandlers();
+ process.on('newListener', startListeningIfSignal);
+ process.on('removeListener', stopListeningIfSignal);
+
+ if (getOptionValue('--experimental-report')) {
+ const {
+ config,
+ handleSignal
+ } = require('internal/process/report');
+ if (config.events.includes('signal')) {
+ process.on(config.signal, handleSignal);
+ }
+ }
+}
+
function setupTraceCategoryState() {
const {
asyncHooksEnabledInitial,