ensure termination of child dtrace on CLI term by a signal
This commit is contained in:
parent
77b556d245
commit
4d0f6aeb96
2 changed files with 20 additions and 1 deletions
|
@ -2,7 +2,9 @@
|
||||||
|
|
||||||
## bunyan 0.16.1 (not yet released)
|
## bunyan 0.16.1 (not yet released)
|
||||||
|
|
||||||
(nothing yet)
|
- Ensure that a possible dtrace child process (with using `bunyan -p PID`) is
|
||||||
|
terminated on signal termination of the bunyan CLI (at least for SIGINT,
|
||||||
|
SIGQUIT, SIGTERM, SIGHUP).
|
||||||
|
|
||||||
|
|
||||||
## bunyan 0.16.0
|
## bunyan 0.16.0
|
||||||
|
|
17
bin/bunyan
17
bin/bunyan
|
@ -65,6 +65,9 @@ Object.keys(levelFromName).forEach(function (name) {
|
||||||
// The current raw input line being processed. Used for `uncaughtException`.
|
// The current raw input line being processed. Used for `uncaughtException`.
|
||||||
var currLine = null;
|
var currLine = null;
|
||||||
|
|
||||||
|
// Child dtrace process, if any. Used for signal-handling.
|
||||||
|
var child = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---- support functions
|
//---- support functions
|
||||||
|
@ -905,6 +908,7 @@ function processPid(opts, stylize, callback) {
|
||||||
var argv = ['dtrace', '-Z', '-x', 'strsize=4k', '-qn',
|
var argv = ['dtrace', '-Z', '-x', 'strsize=4k', '-qn',
|
||||||
format('bunyan%d:::log-*{printf("%s", copyinstr(arg0))}', opts.pid)];
|
format('bunyan%d:::log-*{printf("%s", copyinstr(arg0))}', opts.pid)];
|
||||||
var dtrace = spawn(argv[0], argv.slice(1));
|
var dtrace = spawn(argv[0], argv.slice(1));
|
||||||
|
child = dtrace; // intentionall global
|
||||||
|
|
||||||
dtrace.stderr.pipe(process.stderr);
|
dtrace.stderr.pipe(process.stderr);
|
||||||
|
|
||||||
|
@ -1023,6 +1027,19 @@ function asyncForEach(arr, iterator, callback) {
|
||||||
|
|
||||||
//---- mainline
|
//---- mainline
|
||||||
|
|
||||||
|
// Try to ensure we close a child 'dtrace' process on signalled exit.
|
||||||
|
function signalCleanupAndExit(signal) {
|
||||||
|
if (child) {
|
||||||
|
child.kill(signal);
|
||||||
|
}
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
process.on('SIGINT', function () { signalCleanupAndExit('SIGINT'); });
|
||||||
|
process.on('SIGQUIT', function () { signalCleanupAndExit('SIGQUIT'); });
|
||||||
|
process.on('SIGTERM', function () { signalCleanupAndExit('SIGTERM'); });
|
||||||
|
process.on('SIGHUP', function () { signalCleanupAndExit('SIGHUP'); });
|
||||||
|
|
||||||
|
|
||||||
process.on('uncaughtException', function (err) {
|
process.on('uncaughtException', function (err) {
|
||||||
function indent(s) {
|
function indent(s) {
|
||||||
var lines = s.split(/\r?\n/);
|
var lines = s.split(/\r?\n/);
|
||||||
|
|
Loading…
Reference in a new issue