Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: #11284
PR-URL: #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>
  • Loading branch information
cjihrig committed Feb 14, 2017
commit 784eb2fd65ab0e17f3ec15b801c8e9d78866681a
13 changes: 9 additions & 4 deletions src/spawn_sync.cc
Original file line number Diff line number Diff line change
Expand Up @@ -650,12 +650,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(),
Expand Down
5 changes: 2 additions & 3 deletions test/parallel/test-child-process-spawnsync-kill-signal.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
'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) {
const child = cp.spawnSync(process.execPath,
[__filename, 'child'],
{killSignal, timeout: 100});

assert.strictEqual(child.status, exitCode);
assert.strictEqual(child.status, null);
assert.strictEqual(child.error.code, 'ETIMEDOUT');
return child;
}
Expand Down