Browse Source

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 <santiago.gimeno@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
v6.x
cjihrig 8 years ago
committed by Myles Borins
parent
commit
947d07bd87
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 13
      src/spawn_sync.cc
  2. 5
      test/parallel/test-child-process-spawnsync-kill-signal.js

13
src/spawn_sync.cc

@ -645,12 +645,17 @@ Local<Object> SyncProcessRunner::BuildResultObject() {
Integer::New(env()->isolate(), GetError()));
}
if (exit_status_ >= 0)
js_result->Set(env()->status_string(),
Number::New(env()->isolate(), static_cast<double>(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<double>(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(),

5
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;
}

Loading…
Cancel
Save