summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Yuan <me@yhndnzj.com>2023-12-25 12:21:07 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-12-25 15:19:44 +0100
commit245841a872a09f6325bb830247533a3671400085 (patch)
tree10d741637d8d1de79dfbd8cef60f90c989a75ddd
parentnetwork: use RET_GATHER() macro (diff)
downloadsystemd-245841a872a09f6325bb830247533a3671400085.tar.xz
systemd-245841a872a09f6325bb830247533a3671400085.zip
core/unit: don't log 0 values in unit_log_resources
Prompted by #30573
-rw-r--r--src/core/unit.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/core/unit.c b/src/core/unit.c
index c5d8483791..011261a7fc 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -2398,26 +2398,30 @@ static int unit_log_resources(Unit *u) {
}
for (CGroupMemoryAccountingMetric metric = 0; metric <= _CGROUP_MEMORY_ACCOUNTING_METRIC_CACHED_LAST; metric++) {
- uint64_t v = UINT64_MAX;
+ uint64_t value = UINT64_MAX;
assert(memory_fields[metric].journal_field);
assert(memory_fields[metric].message_suffix);
- (void) unit_get_memory_accounting(u, metric, &v);
- if (v == UINT64_MAX)
+ (void) unit_get_memory_accounting(u, metric, &value);
+ if (value == UINT64_MAX)
continue;
- if (asprintf(&t, "%s=%" PRIu64, memory_fields[metric].journal_field, v) < 0)
+ if (asprintf(&t, "%s=%" PRIu64, memory_fields[metric].journal_field, value) < 0)
return log_oom();
iovec[n_iovec++] = IOVEC_MAKE_STRING(TAKE_PTR(t));
+ /* If value is 0, we don't log it in the MESSAGE= field. */
+ if (value == 0)
+ continue;
+
if (strextendf_with_separator(&message, ", ", "%s %s",
- FORMAT_BYTES(v), memory_fields[metric].message_suffix) < 0)
+ FORMAT_BYTES(value), memory_fields[metric].message_suffix) < 0)
return log_oom();
log_level = raise_level(log_level,
- v > MENTIONWORTHY_MEMORY_BYTES,
- v > NOTICEWORTHY_MEMORY_BYTES);
+ value > MENTIONWORTHY_MEMORY_BYTES,
+ value > NOTICEWORTHY_MEMORY_BYTES);
}
for (CGroupIOAccountingMetric k = 0; k < _CGROUP_IO_ACCOUNTING_METRIC_MAX; k++) {
@@ -2434,6 +2438,10 @@ static int unit_log_resources(Unit *u) {
return log_oom();
iovec[n_iovec++] = IOVEC_MAKE_STRING(TAKE_PTR(t));
+ /* If value is 0, we don't log it in the MESSAGE= field. */
+ if (value == 0)
+ continue;
+
/* Format the IO accounting data for inclusion in the human language message string, but only
* for the bytes counters (and not for the operations counters) */
if (io_fields[k].message_suffix) {
@@ -2461,6 +2469,10 @@ static int unit_log_resources(Unit *u) {
return log_oom();
iovec[n_iovec++] = IOVEC_MAKE_STRING(TAKE_PTR(t));
+ /* If value is 0, we don't log it in the MESSAGE= field. */
+ if (value == 0)
+ continue;
+
/* Format the IP accounting data for inclusion in the human language message string, but only
* for the bytes counters (and not for the packets counters) */
if (ip_fields[m].message_suffix) {