]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Replace format_bytes_cgroup_protection with FORMAT_BYTES_CGROUP_PROTECTION
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 6 Jul 2021 08:22:03 +0000 (10:22 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 9 Jul 2021 09:11:25 +0000 (11:11 +0200)
src/basic/format-util.h
src/oom/oomd-util.c
src/systemctl/systemctl-show.c

index e802a0bb1c5255702fd384a75170beafd51f4d74..92bb131a91b86b1624a81309aa9f92d5abea0bc1 100644 (file)
@@ -86,10 +86,4 @@ static inline char *format_bytes(char *buf, size_t l, uint64_t t) {
 #define FORMAT_BYTES(t) format_bytes((char[FORMAT_BYTES_MAX]){}, FORMAT_BYTES_MAX, t)
 #define FORMAT_BYTES_FULL(t, flag) format_bytes_full((char[FORMAT_BYTES_MAX]){}, FORMAT_BYTES_MAX, t, flag)
 
-static inline char *format_bytes_cgroup_protection(char *buf, size_t l, uint64_t t) {
-        if (t == CGROUP_LIMIT_MAX) {
-                (void) snprintf(buf, l, "%s", "infinity");
-                return buf;
-        }
-        return format_bytes(buf, l, t);
-}
+#define FORMAT_BYTES_CGROUP_PROTECTION(t) (t == CGROUP_LIMIT_MAX ? "infinity" : FORMAT_BYTES(t))
index 4bf7db8c3e4b5031a2402910de51a3eea0a8c387..ff0fc13c6faeec09db3a6bbfcde80e46d6f8bbd2 100644 (file)
@@ -521,8 +521,6 @@ void oomd_dump_swap_cgroup_context(const OomdCGroupContext *ctx, FILE *f, const
 }
 
 void oomd_dump_memory_pressure_cgroup_context(const OomdCGroupContext *ctx, FILE *f, const char *prefix) {
-        char mem_min[FORMAT_BYTES_MAX], mem_low[FORMAT_BYTES_MAX];
-
         assert(ctx);
         assert(f);
 
@@ -546,8 +544,8 @@ void oomd_dump_memory_pressure_cgroup_context(const OomdCGroupContext *ctx, FILE
                         "%s\tMemory Low: %s\n"
                         "%s\tPgscan: %" PRIu64 "\n"
                         "%s\tLast Pgscan: %" PRIu64 "\n",
-                        strempty(prefix), format_bytes_cgroup_protection(mem_min, sizeof(mem_min), ctx->memory_min),
-                        strempty(prefix), format_bytes_cgroup_protection(mem_low, sizeof(mem_low), ctx->memory_low),
+                        strempty(prefix), FORMAT_BYTES_CGROUP_PROTECTION(ctx->memory_min),
+                        strempty(prefix), FORMAT_BYTES_CGROUP_PROTECTION(ctx->memory_low),
                         strempty(prefix), ctx->pgscan,
                         strempty(prefix), ctx->last_pgscan);
 }
index 00b6948cdf74ddd94e408101be0dafe6fb13099c..fa9a9ab75070e40e21f791e723d79a17c622371e 100644 (file)
@@ -671,16 +671,15 @@ static void print_status_info(
                     i->memory_swap_max != CGROUP_LIMIT_MAX ||
                     i->memory_available != CGROUP_LIMIT_MAX ||
                     i->memory_limit != CGROUP_LIMIT_MAX) {
-                        char buf[FORMAT_BYTES_MAX];
                         const char *prefix = "";
 
                         printf(" (");
                         if (i->memory_min > 0) {
-                                printf("%smin: %s", prefix, format_bytes_cgroup_protection(buf, sizeof(buf), i->memory_min));
+                                printf("%smin: %s", prefix, FORMAT_BYTES_CGROUP_PROTECTION(i->memory_min));
                                 prefix = " ";
                         }
                         if (i->memory_low > 0) {
-                                printf("%slow: %s", prefix, format_bytes_cgroup_protection(buf, sizeof(buf), i->memory_low));
+                                printf("%slow: %s", prefix, FORMAT_BYTES_CGROUP_PROTECTION(i->memory_low));
                                 prefix = " ";
                         }
                         if (i->memory_high != CGROUP_LIMIT_MAX) {