[Pkg-javascript-commits] [node-foreground-child] 03/69: Enforce that parent always gets a 'exit' event
Bastien Roucariès
rouca at moszumanska.debian.org
Fri Aug 25 11:43:01 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 851bd98fd5a14c68f89423a6848d3425660ebab0
Author: isaacs <i at izs.me>
Date: Fri May 15 15:22:57 2015 -0700
Enforce that parent always gets a 'exit' event
---
index.js | 8 +++++++-
test/basic.js | 42 +++++++++++++++++++++++++++++++++++++++++-
2 files changed, 48 insertions(+), 2 deletions(-)
diff --git a/index.js b/index.js
index 275d44a..37114f1 100644
--- a/index.js
+++ b/index.js
@@ -20,13 +20,19 @@ module.exports = function (program, args) {
} catch (er) {}
})
- process.on('exit', function (code) {
+ process.once('exit', function (code) {
+ emittedExit = true
child.kill('SIGHUP')
})
+ var emittedExit = false
+
child.on('close', function (code, signal) {
if (signal) {
process.removeAllListeners(signal)
+ if (!emittedExit) {
+ process.emit('exit', code)
+ }
process.kill(process.pid, signal)
} else {
process.exit(code)
diff --git a/test/basic.js b/test/basic.js
index 0d18edb..6713aff 100644
--- a/test/basic.js
+++ b/test/basic.js
@@ -9,6 +9,7 @@ if (process.argv[2] === 'child') {
case 'SIGKILL':
process.kill(process.pid, process.argv[3])
break
+
case '0':
case '1':
case '2':
@@ -22,7 +23,24 @@ if (process.argv[2] === 'child') {
if (process.argv[2] === 'parent') {
var program = process.execPath
var args = [__filename, 'child'].concat(process.argv.slice(3))
- fg(program, args)
+ var child = fg(program, args)
+
+ if (process.argv[3] === 'signalexit') {
+ process.on('exit', function () {
+ console.log('parent exit')
+ })
+ switch (process.argv[4]) {
+ case 'parent':
+ process.kill(process.pid, 'SIGTERM')
+ break
+ case 'child':
+ process.kill(child.pid, 'SIGTERM')
+ break
+ default:
+ process.exit()
+ break
+ }
+ }
return
}
@@ -70,3 +88,25 @@ t.test('exit codes', function (t) {
})
t.end()
})
+
+t.test('parent emits exit when SIGTERMed', function (t) {
+ var which = ['parent', 'child', 'nobody']
+ which.forEach(function (who) {
+ t.test('SIGTERM ' + who, function (t) {
+ var prog = process.execPath
+ var args = [__filename, 'parent', 'signalexit', who]
+ 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()
+})
--
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