Browse Source

core: Mark exit() calls with status codes

Also, exit with 128+n for signal exit n, as is The Unix Way.
v0.9.11-release
isaacs 12 years ago
parent
commit
95862b2380
  1. 21
      src/node.cc
  2. 5
      test/simple/test-cluster-master-error.js

21
src/node.cc

@ -1337,13 +1337,13 @@ Local<Value> ExecuteString(Handle<String> source, Handle<Value> filename) {
Local<v8::Script> script = v8::Script::Compile(source, filename); Local<v8::Script> script = v8::Script::Compile(source, filename);
if (script.IsEmpty()) { if (script.IsEmpty()) {
ReportException(try_catch, true); ReportException(try_catch, true);
exit(1); exit(3);
} }
Local<Value> result = script->Run(); Local<Value> result = script->Run();
if (result.IsEmpty()) { if (result.IsEmpty()) {
ReportException(try_catch, true); ReportException(try_catch, true);
exit(1); exit(4);
} }
return scope.Close(result); return scope.Close(result);
@ -1966,7 +1966,7 @@ static void OnFatalError(const char* location, const char* message) {
} else { } else {
fprintf(stderr, "FATAL ERROR: %s\n", message); fprintf(stderr, "FATAL ERROR: %s\n", message);
} }
exit(1); exit(5);
} }
void FatalException(TryCatch &try_catch) { void FatalException(TryCatch &try_catch) {
@ -1981,7 +1981,7 @@ void FatalException(TryCatch &try_catch) {
// failed before the process._fatalException function was added! // failed before the process._fatalException function was added!
// this is probably pretty bad. Nothing to do but report and exit. // this is probably pretty bad. Nothing to do but report and exit.
ReportException(try_catch, true); ReportException(try_catch, true);
exit(1); exit(6);
} }
Local<Function> fatal_f = Local<Function>::Cast(fatal_v); Local<Function> fatal_f = Local<Function>::Cast(fatal_v);
@ -1997,12 +1997,12 @@ void FatalException(TryCatch &try_catch) {
if (fatal_try_catch.HasCaught()) { if (fatal_try_catch.HasCaught()) {
// the fatal exception function threw, so we must exit // the fatal exception function threw, so we must exit
ReportException(fatal_try_catch, true); ReportException(fatal_try_catch, true);
exit(1); exit(7);
} }
if (false == caught->BooleanValue()) { if (false == caught->BooleanValue()) {
ReportException(try_catch, true); ReportException(try_catch, true);
exit(1); exit(8);
} }
} }
@ -2488,7 +2488,7 @@ static void AtExit() {
static void SignalExit(int signal) { static void SignalExit(int signal) {
uv_tty_reset_mode(); uv_tty_reset_mode();
_exit(1); _exit(128 + signal);
} }
@ -2537,8 +2537,7 @@ void Load(Handle<Object> process_l) {
f->Call(global, 1, args); f->Call(global, 1, args);
if (try_catch.HasCaught()) { if (try_catch.HasCaught()) {
ReportException(try_catch, true); FatalException(try_catch);
exit(11);
} }
} }
@ -2568,7 +2567,7 @@ static void ParseDebugOpt(const char* arg) {
if (p) fprintf(stderr, "Debug port must be in range 1025 to 65535.\n"); if (p) fprintf(stderr, "Debug port must be in range 1025 to 65535.\n");
PrintHelp(); PrintHelp();
exit(1); exit(12);
} }
static void PrintHelp() { static void PrintHelp() {
@ -2632,7 +2631,7 @@ static void ParseArgs(int argc, char **argv) {
// argument to -p and --print is optional // argument to -p and --print is optional
if (is_eval == true && i + 1 >= argc) { if (is_eval == true && i + 1 >= argc) {
fprintf(stderr, "Error: %s requires an argument\n", arg); fprintf(stderr, "Error: %s requires an argument\n", arg);
exit(1); exit(13);
} }
print_eval = print_eval || is_print; print_eval = print_eval || is_print;

5
test/simple/test-cluster-master-error.js

@ -62,7 +62,8 @@ if (cluster.isWorker) {
// throw accidently error // throw accidently error
process.nextTick(function() { process.nextTick(function() {
throw 'accidently error'; console.error('about to throw');
throw new Error('accidently error');
}); });
} }
@ -110,7 +111,7 @@ if (cluster.isWorker) {
master.on('exit', function(code) { master.on('exit', function(code) {
// Check that the cluster died accidently // Check that the cluster died accidently
existMaster = (code === 1); existMaster = !!code;
// Give the workers time to shut down // Give the workers time to shut down
setTimeout(checkWorkers, 200); setTimeout(checkWorkers, 200);

Loading…
Cancel
Save