1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-09 12:58:26 +03:00

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.
This commit is contained in:
Lennart Poettering 2018-11-13 20:51:31 +01:00 committed by Zbigniew Jędrzejewski-Szmek
parent 6eb65e7ca4
commit 8204470252

View File

@ -2178,12 +2178,12 @@ void unit_trigger_notify(Unit *u) {
static int unit_log_resources(Unit *u) { static int unit_log_resources(Unit *u) {
struct iovec iovec[1 + _CGROUP_IP_ACCOUNTING_METRIC_MAX + 4]; 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; _cleanup_free_ char *igress = NULL, *egress = NULL;
size_t n_message_parts = 0, n_iovec = 0; size_t n_message_parts = 0, n_iovec = 0;
char* message_parts[3 + 1], *t; char* message_parts[3 + 1], *t;
nsec_t nsec = NSEC_INFINITY; nsec_t nsec = NSEC_INFINITY;
CGroupIPAccountingMetric m; CGroupIPAccountingMetric m;
bool any_traffic = false;
size_t i; size_t i;
int r; int r;
const char* const ip_fields[_CGROUP_IP_ACCOUNTING_METRIC_MAX] = { 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); (void) unit_get_ip_accounting(u, m, &value);
if (value == UINT64_MAX) if (value == UINT64_MAX)
continue; continue;
have_ip_accounting = true;
if (value > 0) if (value > 0)
any_traffic = true; any_traffic = true;
@ -2259,21 +2261,24 @@ static int unit_log_resources(Unit *u) {
} }
} }
if (any_traffic) { if (have_ip_accounting) {
if (igress) if (any_traffic) {
message_parts[n_message_parts++] = TAKE_PTR(igress); if (igress)
if (egress) message_parts[n_message_parts++] = TAKE_PTR(igress);
message_parts[n_message_parts++] = TAKE_PTR(egress); if (egress)
} else { message_parts[n_message_parts++] = TAKE_PTR(egress);
char *k;
k = strdup("no IP traffic"); } else {
if (!k) { char *k;
r = log_oom();
goto finish; k = strdup("no IP traffic");
if (!k) {
r = log_oom();
goto finish;
}
message_parts[n_message_parts++] = k;
} }
message_parts[n_message_parts++] = k;
} }
/* Is there any accounting data available at all? */ /* Is there any accounting data available at all? */