diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-05-20 22:13:08 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-05-31 14:30:23 +0200 |
commit | 9be391d4dbe1e5f83e44486c1a2a91ab0327be6c (patch) | |
tree | 3e99770a3174b5e4432e96520227fae9ab36c51f /src/shared/logs-show.c | |
parent | 324d6aa92629d4368b517f5c4d17a103c69098be (diff) | |
download | systemd-9be391d4dbe1e5f83e44486c1a2a91ab0327be6c.tar.gz systemd-9be391d4dbe1e5f83e44486c1a2a91ab0327be6c.tar.bz2 systemd-9be391d4dbe1e5f83e44486c1a2a91ab0327be6c.zip |
shared/logs-show: use _cleanup_
Diffstat (limited to 'src/shared/logs-show.c')
-rw-r--r-- | src/shared/logs-show.c | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 124fa838b3..365c913009 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -862,12 +862,10 @@ static int output_json( } } } - if (r == -EBADMSG) { log_debug_errno(r, "Skipping message we can't read: %m"); return 0; } - if (r < 0) return r; @@ -877,7 +875,8 @@ static int output_json( SD_JOURNAL_FOREACH_DATA(j, data, length) { const char *eq; - char *kk, *n; + char *kk; + _cleanup_free_ char *n = NULL; size_t m; unsigned u; @@ -890,33 +889,24 @@ static int output_json( continue; m = eq - (const char*) data; - n = memdup_suffix0(data, m); if (!n) { r = log_oom(); goto finish; } - if (output_fields && !set_get(output_fields, n)) { - free(n); + if (output_fields && !set_get(output_fields, n)) continue; - } - if (separator) { - if (mode == OUTPUT_JSON_PRETTY) - fputs(",\n\t", f); - else - fputs(", ", f); - } + if (separator) + fputs(mode == OUTPUT_JSON_PRETTY ? ",\n\t" : ", ", f); u = PTR_TO_UINT(hashmap_get2(h, n, (void**) &kk)); - if (u == 0) { + if (u == 0) /* We already printed this, let's jump to the next */ - free(n); separator = false; - continue; - } else if (u == 1) { + else if (u == 1) { /* Field only appears once, output it directly */ json_escape(f, data, m, flags); @@ -926,12 +916,9 @@ static int output_json( hashmap_remove(h, n); free(kk); - free(n); separator = true; - continue; - } else { /* Field appears multiple times, output it as array */ json_escape(f, data, m, flags); @@ -958,7 +945,6 @@ static int output_json( hashmap_remove(h, n); free(kk); - free(n); /* Iterate data fields form the beginning */ done = false; |