From 95862b23802175b5d6b509d6a6f83fa5fd53b474 Mon Sep 17 00:00:00 2001 From: isaacs Date: Wed, 27 Feb 2013 11:23:20 -0800 Subject: [PATCH] core: Mark exit() calls with status codes Also, exit with 128+n for signal exit n, as is The Unix Way. --- src/node.cc | 21 ++++++++++----------- test/simple/test-cluster-master-error.js | 5 +++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/node.cc b/src/node.cc index 74bfc52566..74f299394f 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1337,13 +1337,13 @@ Local ExecuteString(Handle source, Handle filename) { Local script = v8::Script::Compile(source, filename); if (script.IsEmpty()) { ReportException(try_catch, true); - exit(1); + exit(3); } Local result = script->Run(); if (result.IsEmpty()) { ReportException(try_catch, true); - exit(1); + exit(4); } return scope.Close(result); @@ -1966,7 +1966,7 @@ static void OnFatalError(const char* location, const char* message) { } else { fprintf(stderr, "FATAL ERROR: %s\n", message); } - exit(1); + exit(5); } void FatalException(TryCatch &try_catch) { @@ -1981,7 +1981,7 @@ void FatalException(TryCatch &try_catch) { // failed before the process._fatalException function was added! // this is probably pretty bad. Nothing to do but report and exit. ReportException(try_catch, true); - exit(1); + exit(6); } Local fatal_f = Local::Cast(fatal_v); @@ -1997,12 +1997,12 @@ void FatalException(TryCatch &try_catch) { if (fatal_try_catch.HasCaught()) { // the fatal exception function threw, so we must exit ReportException(fatal_try_catch, true); - exit(1); + exit(7); } if (false == caught->BooleanValue()) { ReportException(try_catch, true); - exit(1); + exit(8); } } @@ -2488,7 +2488,7 @@ static void AtExit() { static void SignalExit(int signal) { uv_tty_reset_mode(); - _exit(1); + _exit(128 + signal); } @@ -2537,8 +2537,7 @@ void Load(Handle process_l) { f->Call(global, 1, args); if (try_catch.HasCaught()) { - ReportException(try_catch, true); - exit(11); + FatalException(try_catch); } } @@ -2568,7 +2567,7 @@ static void ParseDebugOpt(const char* arg) { if (p) fprintf(stderr, "Debug port must be in range 1025 to 65535.\n"); PrintHelp(); - exit(1); + exit(12); } static void PrintHelp() { @@ -2632,7 +2631,7 @@ static void ParseArgs(int argc, char **argv) { // argument to -p and --print is optional if (is_eval == true && i + 1 >= argc) { fprintf(stderr, "Error: %s requires an argument\n", arg); - exit(1); + exit(13); } print_eval = print_eval || is_print; diff --git a/test/simple/test-cluster-master-error.js b/test/simple/test-cluster-master-error.js index 5e0e3fac60..ee2ed9eb4e 100644 --- a/test/simple/test-cluster-master-error.js +++ b/test/simple/test-cluster-master-error.js @@ -62,7 +62,8 @@ if (cluster.isWorker) { // throw accidently error 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) { // Check that the cluster died accidently - existMaster = (code === 1); + existMaster = !!code; // Give the workers time to shut down setTimeout(checkWorkers, 200);