Skip to content

Commit

Permalink
core/unit: don't log 0 values in unit_log_resources
Browse files Browse the repository at this point in the history
Prompted by systemd#30573
  • Loading branch information
YHNdnzj committed Dec 25, 2023
1 parent 38617c5 commit f631bf0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/core/unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -2411,6 +2411,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 (v == 0)
continue;

if (strextendf_with_separator(&message, ", ", "%s %s",
FORMAT_BYTES(v), memory_fields[metric].message_suffix) < 0)
return log_oom();
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f631bf0

Please sign in to comment.