[Pkg-javascript-commits] [node-foreground-child] 20/69: Transparently translate high-order exit code to appropriate signal

Bastien Roucariès rouca at moszumanska.debian.org
Fri Aug 25 11:43:02 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-foreground-child.

commit d08660b4fa4ce690b4b82ecfe76a76f5bb8b3071
Author: isaacs <i at izs.me>
Date:   Sat Dec 26 15:36:22 2015 -0800

    Transparently translate high-order exit code to appropriate signal
    
    See https://github.com/nodejs/node/issues/4432
---
 index.js      |  7 +++++++
 package.json  |  1 +
 test/basic.js | 35 +++++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+)

diff --git a/index.js b/index.js
index d002c2e..74711df 100644
--- a/index.js
+++ b/index.js
@@ -1,5 +1,6 @@
 var signalExit = require('signal-exit')
 var spawn = require('win-spawn')
+var codeToSignal = require('code-to-signal')
 
 module.exports = function (program, args, cb) {
   var arrayIndex = arguments.length
@@ -31,12 +32,18 @@ module.exports = function (program, args, cb) {
 
   var childExited = false
   signalExit(function (code, signal) {
+    if (code > 128 && !signal)
+      signal = codeToSignal(code)
+
     child.kill(signal || 'SIGHUP')
   })
 
   child.on('close', function (code, signal) {
     cb(function () {
       childExited = true
+      if (code > 128 && !signal)
+        signal = codeToSignal(code)
+
       if (signal) {
         // If there is nothing else keeping the event loop alive,
         // then there's a race between a graceful exit and getting
diff --git a/package.json b/package.json
index d45a61b..01e82ea 100644
--- a/package.json
+++ b/package.json
@@ -7,6 +7,7 @@
     "test": "test"
   },
   "dependencies": {
+    "code-to-signal": "^1.0.2",
     "signal-exit": "^2.0.0",
     "win-spawn": "^2.0.0"
   },
diff --git a/test/basic.js b/test/basic.js
index d8017a9..a677981 100644
--- a/test/basic.js
+++ b/test/basic.js
@@ -124,6 +124,37 @@ t.test('parent emits exit when SIGTERMed', { skip: isZero10OnTravis() }, functio
   t.end()
 })
 
+
+t.test('signals using sh', { skip: isWindows() }, function (t) {
+  var which = ['parent', 'child', 'nobody']
+  which.forEach(function (who) {
+    t.test('SIGTERM ' + who, function (t) {
+      var prog = '/bin/sh'
+      var cmd = [
+        process.execPath,
+        __filename,
+        'parent',
+        'signalexit',
+        who
+      ].join(' ')
+      var args = ['-c', cmd]
+      var child = spawn(prog, args)
+      var out = ''
+      child.stdout.on('data', function (c) { out += c })
+      child.on('close', function (code, signal) {
+        if (who === 'nobody')
+          t.equal(signal, null)
+        else
+          t.equal(signal, 'SIGTERM')
+        t.equal(out, 'parent exit\n')
+        t.end()
+      })
+    })
+  })
+  t.end()
+})
+
+
 t.test('beforeExitHandler', function (t) {
   var codes = [0, 1, 2]
   codes.forEach(function (c) {
@@ -148,3 +179,7 @@ function isZero10OnTravis () {
   return process.env.TRAVIS && /^v0\.10\.[0-9]+$/.test(process.version) ?
     'skip on 0.10 on Travis' : false
 }
+
+function isWindows () {
+  return process.platform === 'win32' && 'skip on windows'
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-foreground-child.git



More information about the Pkg-javascript-commits mailing list