diff options
author | Sam Roberts <vieuxtech@gmail.com> | 2020-03-25 22:37:39 +0300 |
---|---|---|
committer | Sam Roberts <vieuxtech@gmail.com> | 2020-03-31 21:59:25 +0300 |
commit | 867ff41d87e292997ff2ceb8d77e715145aed7b7 (patch) | |
tree | 69de511deeaee8d09ea5cd5e5c4aefebc1382bf0 /src/node_report.cc | |
parent | e158218fb23ae7cea7aa5d27ee2092a4b6d96184 (diff) |
src: handle report options on fatalerror
Follow on to https://github.com/nodejs/node/pull/32207, 3 other options
are also not respected under situations that the isolate is not
available.
PR-URL: https://github.com/nodejs/node/pull/32497
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/node_report.cc')
-rw-r--r-- | src/node_report.cc | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/src/node_report.cc b/src/node_report.cc index bb703594c9a..ff2206dbb44 100644 --- a/src/node_report.cc +++ b/src/node_report.cc @@ -32,7 +32,6 @@ using node::DiagnosticFilename; using node::Environment; using node::Mutex; using node::NativeSymbolDebuggingContext; -using node::PerIsolateOptions; using node::TIME_TYPE; using node::worker::Worker; using v8::HeapSpaceStatistics; @@ -45,6 +44,8 @@ using v8::String; using v8::V8; using v8::Value; +namespace per_process = node::per_process; + // Internal/static function declarations static void WriteNodeReport(Isolate* isolate, Environment* env, @@ -70,8 +71,6 @@ static void PrintCpuInfo(JSONWriter* writer); static void PrintNetworkInterfaceInfo(JSONWriter* writer); // External function to trigger a report, writing to file. -// The 'name' parameter is in/out: an input filename is used -// if supplied, and the actual filename is returned. std::string TriggerNodeReport(Isolate* isolate, Environment* env, const char* message, @@ -79,20 +78,25 @@ std::string TriggerNodeReport(Isolate* isolate, const std::string& name, Local<String> stackstr) { std::string filename; - std::shared_ptr<PerIsolateOptions> options; - if (env != nullptr) options = env->isolate_data()->options(); // Determine the required report filename. In order of priority: // 1) supplied on API 2) configured on startup 3) default generated if (!name.empty()) { // Filename was specified as API parameter. filename = name; - } else if (env != nullptr && options->report_filename.length() > 0) { - // File name was supplied via start-up option. - filename = options->report_filename; } else { - filename = *DiagnosticFilename(env != nullptr ? env->thread_id() : 0, - "report", "json"); + std::string report_filename; + { + Mutex::ScopedLock lock(per_process::cli_options_mutex); + report_filename = per_process::cli_options->report_filename; + } + if (report_filename.length() > 0) { + // File name was supplied via start-up option. + filename = report_filename; + } else { + filename = *DiagnosticFilename(env != nullptr ? env->thread_id() : 0, + "report", "json"); + } } // Open the report file stream for writing. Supports stdout/err, @@ -104,9 +108,14 @@ std::string TriggerNodeReport(Isolate* isolate, } else if (filename == "stderr") { outstream = &std::cerr; } else { + std::string report_directory; + { + Mutex::ScopedLock lock(per_process::cli_options_mutex); + report_directory = per_process::cli_options->report_directory; + } // Regular file. Append filename to directory path if one was specified - if (env != nullptr && options->report_directory.length() > 0) { - std::string pathname = options->report_directory; + if (report_directory.length() > 0) { + std::string pathname = report_directory; pathname += node::kPathSeparator; pathname += filename; outfile.open(pathname, std::ios::out | std::ios::binary); @@ -117,8 +126,8 @@ std::string TriggerNodeReport(Isolate* isolate, if (!outfile.is_open()) { std::cerr << "\nFailed to open Node.js report file: " << filename; - if (env != nullptr && options->report_directory.length() > 0) - std::cerr << " directory: " << options->report_directory; + if (report_directory.length() > 0) + std::cerr << " directory: " << report_directory; std::cerr << " (errno: " << errno << ")" << std::endl; return ""; @@ -127,7 +136,11 @@ std::string TriggerNodeReport(Isolate* isolate, std::cerr << "\nWriting Node.js report to file: " << filename; } - bool compact = env != nullptr ? options->report_compact : true; + bool compact; + { + Mutex::ScopedLock lock(per_process::cli_options_mutex); + compact = per_process::cli_options->report_compact; + } WriteNodeReport(isolate, env, message, trigger, filename, *outstream, stackstr, compact); @@ -136,7 +149,10 @@ std::string TriggerNodeReport(Isolate* isolate, outfile.close(); } - std::cerr << "\nNode.js report completed" << std::endl; + // Do not mix JSON and free-form text on stderr. + if (filename != "stderr") { + std::cerr << "\nNode.js report completed" << std::endl; + } return filename; } |