queue up signal handlers so they do not get overwritten.
This commit is contained in:
parent
ad5ae36a2f
commit
057ab4da03
|
@ -46,11 +46,25 @@ function Bitcoin(options) {
|
||||||
|
|
||||||
Bitcoin.prototype.__proto__ = EventEmitter.prototype;
|
Bitcoin.prototype.__proto__ = EventEmitter.prototype;
|
||||||
|
|
||||||
|
// Make sure signal handlers are not overwritten
|
||||||
|
Bitcoin._signalQueue = [];
|
||||||
|
Bitcoin._processOn = process.on;
|
||||||
|
process.addListener =
|
||||||
|
process.on = function(name, listener) {
|
||||||
|
if (~['SIGINT', 'SIGHUP', 'SIGQUIT'].indexOf(name.toUpperCase())) {
|
||||||
|
if (!Bitcoin.global || !Bitcoin.global._started) {
|
||||||
|
Bitcoin._signalQueue.push([name, listener]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return on.apply(this, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
Bitcoin.prototype.start = function(callback) {
|
Bitcoin.prototype.start = function(callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (this._started) return;
|
if (this._startCalled) return;
|
||||||
this._started = true;
|
this._startCalled = true;
|
||||||
|
|
||||||
var none = {};
|
var none = {};
|
||||||
var isSignal = {};
|
var isSignal = {};
|
||||||
|
@ -61,6 +75,8 @@ Bitcoin.prototype.start = function(callback) {
|
||||||
var errorCaught = none;
|
var errorCaught = none;
|
||||||
|
|
||||||
this.log_pipe = bitcoindjs.start(function(err, status) {
|
this.log_pipe = bitcoindjs.start(function(err, status) {
|
||||||
|
self._started = true;
|
||||||
|
|
||||||
[sigint, sighup, sigquit].forEach(function(signal) {
|
[sigint, sighup, sigquit].forEach(function(signal) {
|
||||||
process.on(signal.name, signal.listener = function() {
|
process.on(signal.name, signal.listener = function() {
|
||||||
if (process.listeners(signal.name).length > 1) {
|
if (process.listeners(signal.name).length > 1) {
|
||||||
|
@ -75,6 +91,12 @@ Bitcoin.prototype.start = function(callback) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Finally set signal handlers
|
||||||
|
process.on = process.addListener = Bitcoind._processOn;
|
||||||
|
Bitcoin._signalQueue.forEach(function(event) {
|
||||||
|
process.on(event[0], event[1]);
|
||||||
|
});
|
||||||
|
|
||||||
var exit = process.exit;
|
var exit = process.exit;
|
||||||
self._exit = function() {
|
self._exit = function() {
|
||||||
return exit.apply(process, arguments);
|
return exit.apply(process, arguments);
|
||||||
|
|
|
@ -478,6 +478,7 @@ start_node(void) {
|
||||||
// drop the bitcoind signal handlers - we want our own
|
// drop the bitcoind signal handlers - we want our own
|
||||||
signal(SIGINT, SIG_DFL);
|
signal(SIGINT, SIG_DFL);
|
||||||
signal(SIGHUP, SIG_DFL);
|
signal(SIGHUP, SIG_DFL);
|
||||||
|
signal(SIGQUIT, SIG_DFL);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue