From: Lennart Poettering Date: Tue, 13 Nov 2018 19:51:31 +0000 (+0100) Subject: unit: don't claim there was no IP traffic generated by a unit when we don't know X-Git-Tag: v240~331 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8204470252684a5dc2050382944f1b589a0d6992;p=thirdparty%2Fsystemd.git unit: don't claim there was no IP traffic generated by a unit when we don't know Only if we have some IP traffic accounting at all we should claim that. --- diff --git a/src/core/unit.c b/src/core/unit.c index 5359feb3b68..c4a0b49edb6 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -2178,12 +2178,12 @@ void unit_trigger_notify(Unit *u) { static int unit_log_resources(Unit *u) { struct iovec iovec[1 + _CGROUP_IP_ACCOUNTING_METRIC_MAX + 4]; + bool any_traffic = false, have_ip_accounting = false; _cleanup_free_ char *igress = NULL, *egress = NULL; size_t n_message_parts = 0, n_iovec = 0; char* message_parts[3 + 1], *t; nsec_t nsec = NSEC_INFINITY; CGroupIPAccountingMetric m; - bool any_traffic = false; size_t i; int r; const char* const ip_fields[_CGROUP_IP_ACCOUNTING_METRIC_MAX] = { @@ -2230,6 +2230,8 @@ static int unit_log_resources(Unit *u) { (void) unit_get_ip_accounting(u, m, &value); if (value == UINT64_MAX) continue; + + have_ip_accounting = true; if (value > 0) any_traffic = true; @@ -2259,21 +2261,24 @@ static int unit_log_resources(Unit *u) { } } - if (any_traffic) { - if (igress) - message_parts[n_message_parts++] = TAKE_PTR(igress); - if (egress) - message_parts[n_message_parts++] = TAKE_PTR(egress); - } else { - char *k; + if (have_ip_accounting) { + if (any_traffic) { + if (igress) + message_parts[n_message_parts++] = TAKE_PTR(igress); + if (egress) + message_parts[n_message_parts++] = TAKE_PTR(egress); - k = strdup("no IP traffic"); - if (!k) { - r = log_oom(); - goto finish; - } + } else { + char *k; - message_parts[n_message_parts++] = k; + k = strdup("no IP traffic"); + if (!k) { + r = log_oom(); + goto finish; + } + + message_parts[n_message_parts++] = k; + } } /* Is there any accounting data available at all? */