From 1ef175e5a434cd8c8f5bf42cf39df242c07aefd3 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 20 Jan 2019 17:57:07 -0500 Subject: [PATCH] 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);