|
|
923a60 |
From 76d6062ebf93614a45f1f74be7a93a9a662c5812 Mon Sep 17 00:00:00 2001
|
|
|
923a60 |
From: Lennart Poettering <lennart@poettering.net>
|
|
|
923a60 |
Date: Tue, 19 May 2015 00:35:02 +0200
|
|
|
923a60 |
Subject: [PATCH] journalctl: unify how we free boot id lists a bit
|
|
|
923a60 |
|
|
|
923a60 |
Instead of use LIST_FOREACH_SAFE, just use the same, seperate destructor
|
|
|
923a60 |
everywhere.
|
|
|
923a60 |
|
|
|
923a60 |
Cherry-picked from: 9530e0d023b0e9308f19eadf6e42cdc25bc30793
|
|
|
923a60 |
Related: #1318994
|
|
|
923a60 |
---
|
|
|
923a60 |
src/journal/journalctl.c | 21 +++++++++++++++------
|
|
|
923a60 |
1 file changed, 15 insertions(+), 6 deletions(-)
|
|
|
923a60 |
|
|
|
923a60 |
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
|
|
|
923a60 |
index ba9ae05f72..5864ff50a6 100644
|
|
|
923a60 |
--- a/src/journal/journalctl.c
|
|
|
923a60 |
+++ b/src/journal/journalctl.c
|
|
|
923a60 |
@@ -932,6 +932,15 @@ static int add_matches(sd_journal *j, char **args) {
|
|
|
923a60 |
return 0;
|
|
|
923a60 |
}
|
|
|
923a60 |
|
|
|
923a60 |
+static void boot_id_free_all(BootId *l) {
|
|
|
923a60 |
+
|
|
|
923a60 |
+ while (l) {
|
|
|
923a60 |
+ BootId *i = l;
|
|
|
923a60 |
+ LIST_REMOVE(boot_list, l, i);
|
|
|
923a60 |
+ free(i);
|
|
|
923a60 |
+ }
|
|
|
923a60 |
+}
|
|
|
923a60 |
+
|
|
|
923a60 |
static int discover_next_boot(
|
|
|
923a60 |
sd_journal *j,
|
|
|
923a60 |
BootId **boot,
|
|
|
923a60 |
@@ -1009,6 +1018,7 @@ static int discover_next_boot(
|
|
|
923a60 |
|
|
|
923a60 |
*boot = next_boot;
|
|
|
923a60 |
next_boot = NULL;
|
|
|
923a60 |
+
|
|
|
923a60 |
return 0;
|
|
|
923a60 |
}
|
|
|
923a60 |
|
|
|
923a60 |
@@ -1080,9 +1090,7 @@ static int get_boots(
|
|
|
923a60 |
|
|
|
923a60 |
r = discover_next_boot(j, ¤t, advance_older, !query_ref_boot);
|
|
|
923a60 |
if (r < 0) {
|
|
|
923a60 |
- BootId *id, *id_next;
|
|
|
923a60 |
- LIST_FOREACH_SAFE(boot_list, id, id_next, head)
|
|
|
923a60 |
- free(id);
|
|
|
923a60 |
+ boot_id_free_all(head);
|
|
|
923a60 |
return r;
|
|
|
923a60 |
}
|
|
|
923a60 |
|
|
|
923a60 |
@@ -1118,7 +1126,7 @@ finish:
|
|
|
923a60 |
|
|
|
923a60 |
static int list_boots(sd_journal *j) {
|
|
|
923a60 |
int w, i, count;
|
|
|
923a60 |
- BootId *id, *id_next, *all_ids;
|
|
|
923a60 |
+ BootId *id, *all_ids;
|
|
|
923a60 |
|
|
|
923a60 |
assert(j);
|
|
|
923a60 |
|
|
|
923a60 |
@@ -1132,7 +1140,7 @@ static int list_boots(sd_journal *j) {
|
|
|
923a60 |
w = DECIMAL_STR_WIDTH(count - 1) + 1;
|
|
|
923a60 |
|
|
|
923a60 |
i = 0;
|
|
|
923a60 |
- LIST_FOREACH_SAFE(boot_list, id, id_next, all_ids) {
|
|
|
923a60 |
+ LIST_FOREACH(boot_list, id, all_ids) {
|
|
|
923a60 |
char a[FORMAT_TIMESTAMP_MAX], b[FORMAT_TIMESTAMP_MAX];
|
|
|
923a60 |
|
|
|
923a60 |
printf("% *i " SD_ID128_FORMAT_STR " %s—%s\n",
|
|
|
923a60 |
@@ -1141,9 +1149,10 @@ static int list_boots(sd_journal *j) {
|
|
|
923a60 |
format_timestamp_maybe_utc(a, sizeof(a), id->first),
|
|
|
923a60 |
format_timestamp_maybe_utc(b, sizeof(b), id->last));
|
|
|
923a60 |
i++;
|
|
|
923a60 |
- free(id);
|
|
|
923a60 |
}
|
|
|
923a60 |
|
|
|
923a60 |
+ boot_id_free_all(all_ids);
|
|
|
923a60 |
+
|
|
|
923a60 |
return 0;
|
|
|
923a60 |
}
|
|
|
923a60 |
|