This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

use SIGABRT if process.abort isn't available

  • Loading branch information...
davepacheco committed Apr 25, 2012
1 parent 427589f commit ac77f3a546c16b0e19fa53c46d135967b1680f1e
Showing with 36 additions and 11 deletions.
  1. +35 −10 lib/panic.js
  2. +1 −1 package.json
View
@@ -26,11 +26,34 @@
var mod_fs = require('fs'); var mod_fs = require('fs');
var mod_subr = require('./subr'); var mod_subr = require('./subr');
var caPanicSkipDump = false;
var caPanicAbort = false;
/* /*
* Configures the current program to dump saved program state before crashing. * Configures the current program to dump saved program state before crashing.
* The following options may be specified:
*
* abortOnPanic On panic, uses process.abort() (which is abort(3C)) to
* exit the program. On some systems, this causes the OS
* to save a core file that can be used to read JavaScript-
* level state. If process.abort isn't available, SIGABRT
* will be used instead.
*
* skipDump On panic, skips attempting to dump JavaScript-level
* state in JavaScript. This is mostly useful if you've
* also set abortOnPanic, in which case you expect to
* extract JavaScript-level state from the OS core dump and
* don't want node-panic to even try to serialize state
* separatley.
*/ */
function caEnablePanicOnCrash() function caEnablePanicOnCrash(options)
{ {
if (options && options.abortOnPanic)
caPanicAbort = true;
if (options && options.skipDump)
caPanicSkipDump = true;
process.on('uncaughtException', function (ex) { process.on('uncaughtException', function (ex) {
caPanic('panic due to uncaught exception', ex); caPanic('panic due to uncaught exception', ex);
}); });
@@ -70,22 +93,24 @@ function caPanic(str, err)
* If we had child.execSync(), we could get pfiles. :( * If we had child.execSync(), we could get pfiles. :(
*/ */
caPanicLog('writing core dump to ' + process.cwd() + '/' + if (!caPanicSkipDump) {
filename); caPanicLog('writing core dump to ' + process.cwd() +
caPanicSave(filename); '/' + filename);
caPanicLog('finished writing core dump'); caPanicSave(filename);
caPanicLog('finished writing core dump');
}
} catch (ex) { } catch (ex) {
caPanicWriteSafeError('error during panic', ex); caPanicWriteSafeError('error during panic', ex);
} }
/* if (!caPanicAbort)
* If available, use process.abort() to dump core. Some systems process.exit(1);
* (notably illumos-based systems) can debug Node core dumps.
*/
if (process.abort) if (process.abort)
process.abort(); process.abort();
process.exit(1); for (;;)
process.kill(process.pid, 'SIGABRT');
} }
/* /*
View
@@ -1,6 +1,6 @@
{ {
"name": "panic", "name": "panic",
"version": "0.1.2", "version": "0.2.0",
"description": "Postmortem debugging facility", "description": "Postmortem debugging facility",
"author": "Joyent (joyent.com)", "author": "Joyent (joyent.com)",
"engines": { "node": "*" }, "engines": { "node": "*" },

0 comments on commit ac77f3a

Please sign in to comment.