Skip to content

Commit 0f91e03

Browse files
cjihrigtargos
authored andcommitted
report: simplify rlimit to JSON logic
PR-URL: #25597 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Denys Otrishko <[email protected]>
1 parent a02b621 commit 0f91e03

File tree

1 file changed

+8
-24
lines changed

1 file changed

+8
-24
lines changed

src/node_report.cc

+8-24
Original file line numberDiff line numberDiff line change
@@ -748,36 +748,20 @@ static void PrintSystemInformation(JSONWriter* writer) {
748748

749749
writer->json_objectstart("userLimits");
750750
struct rlimit limit;
751-
char buf[64];
752751
std::string soft, hard;
753752

754753
for (size_t i = 0; i < arraysize(rlimit_strings); i++) {
755754
if (getrlimit(rlimit_strings[i].id, &limit) == 0) {
756-
if (limit.rlim_cur == RLIM_INFINITY) {
755+
if (limit.rlim_cur == RLIM_INFINITY)
757756
soft = std::string("unlimited");
758-
} else {
759-
#if defined(_AIX) || defined(__sun)
760-
snprintf(buf, sizeof(buf), "%ld", limit.rlim_cur);
761-
soft = std::string(buf);
762-
#elif defined(__linux__) && !defined(__GLIBC__)
763-
snprintf(buf, sizeof(buf), "%ld", limit.rlim_cur);
764-
soft = std::string(buf);
765-
#else
766-
snprintf(buf, sizeof(buf), "%16" PRIu64, limit.rlim_cur);
767-
soft = std::string(soft);
768-
#endif
769-
}
770-
if (limit.rlim_max == RLIM_INFINITY) {
757+
else
758+
soft = std::to_string(limit.rlim_cur);
759+
760+
if (limit.rlim_max == RLIM_INFINITY)
771761
hard = std::string("unlimited");
772-
} else {
773-
#ifdef _AIX
774-
snprintf(buf, sizeof(buf), "%lu", limit.rlim_max);
775-
hard = std::string(buf);
776-
#else
777-
snprintf(buf, sizeof(buf), "%llu", limit.rlim_max);
778-
hard = std::string(buf);
779-
#endif
780-
}
762+
else
763+
hard = std::to_string(limit.rlim_max);
764+
781765
writer->json_objectstart(rlimit_strings[i].description);
782766
writer->json_keyvalue("soft", soft);
783767
writer->json_keyvalue("hard", hard);

0 commit comments

Comments
 (0)