From ad2b42e3b6def7d01fdbb7ed5ea013305ed7df41 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 20 Jan 2019 16:38:27 -0500 Subject: [PATCH 1/5] report: remove unnecessary intermediate variable PR-URL: https://github.com/nodejs/node/pull/25597 Reviewed-By: Anna Henningsen Reviewed-By: Refael Ackermann Reviewed-By: Denys Otrishko --- src/node_report_utils.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/node_report_utils.cc b/src/node_report_utils.cc index e93f230d318a6d..bacc9fc3e4bfb9 100644 --- a/src/node_report_utils.cc +++ b/src/node_report_utils.cc @@ -232,8 +232,7 @@ void WalkHandle(uv_handle_t* h, void* arg) { if (h->type == UV_TCP || h->type == UV_NAMED_PIPE || h->type == UV_TTY || h->type == UV_UDP || h->type == UV_POLL) { uv_os_fd_t fd_v; - uv_os_fd_t* fd = &fd_v; - int rc = uv_fileno(h, fd); + int rc = uv_fileno(h, &fd_v); // uv_os_fd_t is an int on Unix and HANDLE on Windows. #ifndef _WIN32 if (rc == 0) { From 04c9f8404bfafc6597d4e3667e7252bc909777e3 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 20 Jan 2019 16:58:24 -0500 Subject: [PATCH 2/5] report: remove unnecessary includes PR-URL: https://github.com/nodejs/node/pull/25597 Reviewed-By: Anna Henningsen Reviewed-By: Refael Ackermann Reviewed-By: Denys Otrishko --- src/node_report_utils.cc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/node_report_utils.cc b/src/node_report_utils.cc index bacc9fc3e4bfb9..f09ee507d3aeb5 100644 --- a/src/node_report_utils.cc +++ b/src/node_report_utils.cc @@ -1,10 +1,5 @@ -#include -#include "env.h" #include "node_internals.h" -#include "node_options.h" #include "node_report.h" -#include "util.h" -#include "v8.h" namespace report { From 5003314e5ac04bc02aa469b5de1878bbb5b918e2 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 20 Jan 2019 17:26:30 -0500 Subject: [PATCH 3/5] report: use uv_pid_t instead of custom PID_TYPE PR-URL: https://github.com/nodejs/node/pull/25597 Reviewed-By: Anna Henningsen Reviewed-By: Refael Ackermann Reviewed-By: Denys Otrishko --- src/node_report.cc | 5 ++--- src/node_report.h | 2 -- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/node_report.cc b/src/node_report.cc index bb4c4e1a3a8e24..f5035d46281d07 100644 --- a/src/node_report.cc +++ b/src/node_report.cc @@ -107,9 +107,8 @@ std::string TriggerNodeReport(Isolate* isolate, // Obtain the current time and the pid (platform dependent) TIME_TYPE tm_struct; - PID_TYPE pid; LocalTime(&tm_struct); - pid = uv_os_getpid(); + uv_pid_t pid = uv_os_getpid(); // Determine the required report filename. In order of priority: // 1) supplied on API 2) configured on startup 3) default generated if (!name.empty()) { @@ -224,7 +223,7 @@ static void WriteNodeReport(Isolate* isolate, Local stackstr, TIME_TYPE* tm_struct) { std::ostringstream buf; - PID_TYPE pid = uv_os_getpid(); + uv_pid_t pid = uv_os_getpid(); // Save formatting for output stream. std::ios old_state(nullptr); diff --git a/src/node_report.h b/src/node_report.h index c64b9c9a20c116..4c29c13afc3670 100644 --- a/src/node_report.h +++ b/src/node_report.h @@ -32,11 +32,9 @@ namespace report { #ifdef _WIN32 typedef SYSTEMTIME TIME_TYPE; -typedef DWORD PID_TYPE; #define PATHSEP "\\" #else // UNIX, OSX typedef struct tm TIME_TYPE; -typedef pid_t PID_TYPE; #define PATHSEP "/" #endif From a0223378b2d2051e7ae05f6e336a56ad53a4635a Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 20 Jan 2019 17:43:53 -0500 Subject: [PATCH 4/5] report: simplify option checking Also update the code for house style. PR-URL: https://github.com/nodejs/node/pull/25597 Reviewed-By: Anna Henningsen Reviewed-By: Refael Ackermann Reviewed-By: Denys Otrishko --- src/node_options.cc | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/node_options.cc b/src/node_options.cc index a3a5e0233aa67c..6d141f52aa624d 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -36,29 +36,45 @@ void PerProcessOptions::CheckOptions(std::vector* errors) { void PerIsolateOptions::CheckOptions(std::vector* errors) { per_env->CheckOptions(errors); #ifdef NODE_REPORT - if (!report_directory.empty() && !per_env->experimental_report) + if (per_env->experimental_report) + return; + + if (!report_directory.empty()) { errors->push_back("--diagnostic-report-directory option is valid only when " "--experimental-report is set"); - if (!report_filename.empty() && !per_env->experimental_report) + } + + if (!report_filename.empty()) { errors->push_back("--diagnostic-report-filename option is valid only when " "--experimental-report is set"); - if (!report_signal.empty() && !per_env->experimental_report) + } + + if (!report_signal.empty()) { errors->push_back("--diagnostic-report-signal option is valid only when " "--experimental-report is set"); - if (report_on_fatalerror && !per_env->experimental_report) + } + + if (report_on_fatalerror) { errors->push_back( "--diagnostic-report-on-fatalerror option is valid only when " "--experimental-report is set"); - if (report_on_signal && !per_env->experimental_report) + } + + if (report_on_signal) { errors->push_back("--diagnostic-report-on-signal option is valid only when " "--experimental-report is set"); - if (report_uncaught_exception && !per_env->experimental_report) + } + + if (report_uncaught_exception) { errors->push_back( "--diagnostic-report-uncaught-exception option is valid only when " "--experimental-report is set"); - if (report_verbose && !per_env->experimental_report) + } + + if (report_verbose) { errors->push_back("--diagnostic-report-verbose option is valid only when " "--experimental-report is set"); + } #endif // NODE_REPORT } From 1ef175e5a434cd8c8f5bf42cf39df242c07aefd3 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 20 Jan 2019 17:57:07 -0500 Subject: [PATCH 5/5] report: simplify rlimit to JSON logic PR-URL: https://github.com/nodejs/node/pull/25597 Reviewed-By: Anna Henningsen Reviewed-By: Refael Ackermann Reviewed-By: Denys Otrishko --- src/node_report.cc | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/src/node_report.cc b/src/node_report.cc index f5035d46281d07..9b936a506d332a 100644 --- a/src/node_report.cc +++ b/src/node_report.cc @@ -748,36 +748,20 @@ static void PrintSystemInformation(JSONWriter* writer) { writer->json_objectstart("userLimits"); struct rlimit limit; - char buf[64]; std::string soft, hard; for (size_t i = 0; i < arraysize(rlimit_strings); i++) { if (getrlimit(rlimit_strings[i].id, &limit) == 0) { - if (limit.rlim_cur == RLIM_INFINITY) { + if (limit.rlim_cur == RLIM_INFINITY) soft = std::string("unlimited"); - } else { -#if defined(_AIX) || defined(__sun) - snprintf(buf, sizeof(buf), "%ld", limit.rlim_cur); - soft = std::string(buf); -#elif defined(__linux__) && !defined(__GLIBC__) - snprintf(buf, sizeof(buf), "%ld", limit.rlim_cur); - soft = std::string(buf); -#else - snprintf(buf, sizeof(buf), "%16" PRIu64, limit.rlim_cur); - soft = std::string(soft); -#endif - } - if (limit.rlim_max == RLIM_INFINITY) { + else + soft = std::to_string(limit.rlim_cur); + + if (limit.rlim_max == RLIM_INFINITY) hard = std::string("unlimited"); - } else { -#ifdef _AIX - snprintf(buf, sizeof(buf), "%lu", limit.rlim_max); - hard = std::string(buf); -#else - snprintf(buf, sizeof(buf), "%llu", limit.rlim_max); - hard = std::string(buf); -#endif - } + else + hard = std::to_string(limit.rlim_max); + writer->json_objectstart(rlimit_strings[i].description); writer->json_keyvalue("soft", soft); writer->json_keyvalue("hard", hard);