From 73c400ad4fa4ffecdf4afb8702c919c99d72586d Mon Sep 17 00:00:00 2001 From: cjihrig Date: Fri, 10 Feb 2017 10:00:19 -0500 Subject: [PATCH] child_process: exit spawnSync with null on signal This commit sets the spawnSync() exit code to null when the child is killed via signal. This brings the behavior more in sync with spawn(). Fixes: https://github.com/nodejs/node/issues/11284 PR-URL: https://github.com/nodejs/node/pull/11288 Reviewed-By: Santiago Gimeno Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Evan Lucas --- src/spawn_sync.cc | 13 +++++++++---- .../test-child-process-spawnsync-kill-signal.js | 5 ++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/spawn_sync.cc b/src/spawn_sync.cc index 79f10a0ea2594d..3fcd61f22a4614 100644 --- a/src/spawn_sync.cc +++ b/src/spawn_sync.cc @@ -645,12 +645,17 @@ Local SyncProcessRunner::BuildResultObject() { Integer::New(env()->isolate(), GetError())); } - if (exit_status_ >= 0) - js_result->Set(env()->status_string(), - Number::New(env()->isolate(), static_cast(exit_status_))); - else + if (exit_status_ >= 0) { + if (term_signal_ > 0) { + js_result->Set(env()->status_string(), Null(env()->isolate())); + } else { + js_result->Set(env()->status_string(), + Number::New(env()->isolate(), static_cast(exit_status_))); + } + } else { // If exit_status_ < 0 the process was never started because of some error. js_result->Set(env()->status_string(), Null(env()->isolate())); + } if (term_signal_ > 0) js_result->Set(env()->signal_string(), diff --git a/test/parallel/test-child-process-spawnsync-kill-signal.js b/test/parallel/test-child-process-spawnsync-kill-signal.js index 8a3c362216eac5..b0d47e0aa68f5c 100644 --- a/test/parallel/test-child-process-spawnsync-kill-signal.js +++ b/test/parallel/test-child-process-spawnsync-kill-signal.js @@ -1,12 +1,11 @@ 'use strict'; -const common = require('../common'); +require('../common'); const assert = require('assert'); const cp = require('child_process'); if (process.argv[2] === 'child') { setInterval(() => {}, 1000); } else { - const exitCode = common.isWindows ? 1 : 0; const { SIGKILL } = process.binding('constants').os.signals; function spawn(killSignal) { @@ -14,7 +13,7 @@ if (process.argv[2] === 'child') { [__filename, 'child'], {killSignal, timeout: 100}); - assert.strictEqual(child.status, exitCode); + assert.strictEqual(child.status, null); assert.strictEqual(child.error.code, 'ETIMEDOUT'); return child; }