report: simplify rlimit to JSON logic
PR-URL: https://github.com/nodejs/node/pull/25597 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
This commit is contained in:
parent
a0223378b2
commit
1ef175e5a4
@ -748,36 +748,20 @@ static void PrintSystemInformation(JSONWriter* writer) {
|
|||||||
|
|
||||||
writer->json_objectstart("userLimits");
|
writer->json_objectstart("userLimits");
|
||||||
struct rlimit limit;
|
struct rlimit limit;
|
||||||
char buf[64];
|
|
||||||
std::string soft, hard;
|
std::string soft, hard;
|
||||||
|
|
||||||
for (size_t i = 0; i < arraysize(rlimit_strings); i++) {
|
for (size_t i = 0; i < arraysize(rlimit_strings); i++) {
|
||||||
if (getrlimit(rlimit_strings[i].id, &limit) == 0) {
|
if (getrlimit(rlimit_strings[i].id, &limit) == 0) {
|
||||||
if (limit.rlim_cur == RLIM_INFINITY) {
|
if (limit.rlim_cur == RLIM_INFINITY)
|
||||||
soft = std::string("unlimited");
|
soft = std::string("unlimited");
|
||||||
} else {
|
else
|
||||||
#if defined(_AIX) || defined(__sun)
|
soft = std::to_string(limit.rlim_cur);
|
||||||
snprintf(buf, sizeof(buf), "%ld", limit.rlim_cur);
|
|
||||||
soft = std::string(buf);
|
if (limit.rlim_max == RLIM_INFINITY)
|
||||||
#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) {
|
|
||||||
hard = std::string("unlimited");
|
hard = std::string("unlimited");
|
||||||
} else {
|
else
|
||||||
#ifdef _AIX
|
hard = std::to_string(limit.rlim_max);
|
||||||
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
|
|
||||||
}
|
|
||||||
writer->json_objectstart(rlimit_strings[i].description);
|
writer->json_objectstart(rlimit_strings[i].description);
|
||||||
writer->json_keyvalue("soft", soft);
|
writer->json_keyvalue("soft", soft);
|
||||||
writer->json_keyvalue("hard", hard);
|
writer->json_keyvalue("hard", hard);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user