From: Yu Watanabe Date: Thu, 25 Apr 2024 01:10:39 +0000 (+0900) Subject: logs-show: rename BootId -> LogId X-Git-Tag: v257-rc1~786^2~7 X-Git-Url: http://git-history.diyao.me/?a=commitdiff_plain;h=6ecee6cf2b38d9ca35de9fd5e2034099aac1870b;p=systemd%2F.git logs-show: rename BootId -> LogId The struct itself is generic, and can be used for other ID. Let's rename it to more generic one. No functional change, just refactoring and preparation for later commits. --- diff --git a/src/journal/journalctl-misc.c b/src/journal/journalctl-misc.c index 2a5d9edfc3..880a0900eb 100644 --- a/src/journal/journalctl-misc.c +++ b/src/journal/journalctl-misc.c @@ -101,8 +101,8 @@ int action_disk_usage(void) { int action_list_boots(void) { _cleanup_(sd_journal_closep) sd_journal *j = NULL; _cleanup_(table_unrefp) Table *table = NULL; - _cleanup_free_ BootId *boots = NULL; - size_t n_boots; + _cleanup_free_ LogId *ids = NULL; + size_t n_ids; int r; assert(arg_action == ACTION_LIST_BOOTS); @@ -115,7 +115,7 @@ int action_list_boots(void) { j, /* advance_older = */ arg_lines_needs_seek_end(), /* max_ids = */ arg_lines >= 0 ? (size_t) arg_lines : SIZE_MAX, - &boots, &n_boots); + &ids, &n_ids); if (r < 0) return log_error_errno(r, "Failed to determine boots: %m"); if (r == 0) @@ -136,7 +136,7 @@ int action_list_boots(void) { (void) table_set_sort(table, (size_t) 0); (void) table_set_reverse(table, 0, arg_reverse); - for (int i = 0; i < (int) n_boots; i++) { + for (int i = 0; i < (int) n_ids; i++) { int index; if (arg_lines_needs_seek_end()) @@ -147,14 +147,14 @@ int action_list_boots(void) { index = i + 1; else /* Otherwise, show negative index. Note, in this case, newer ID is located earlier. */ - index = i + 1 - (int) n_boots; + index = i + 1 - (int) n_ids; r = table_add_many(table, TABLE_INT, index, TABLE_SET_ALIGN_PERCENT, 100, - TABLE_ID128, boots[i].id, - TABLE_TIMESTAMP, boots[i].first_usec, - TABLE_TIMESTAMP, boots[i].last_usec); + TABLE_ID128, ids[i].id, + TABLE_TIMESTAMP, ids[i].first_usec, + TABLE_TIMESTAMP, ids[i].last_usec); if (r < 0) return table_log_add_error(r); } diff --git a/src/libsystemd/sd-journal/test-journal-interleaving.c b/src/libsystemd/sd-journal/test-journal-interleaving.c index d98b3ce8cb..c1b7e23de5 100644 --- a/src/libsystemd/sd-journal/test-journal-interleaving.c +++ b/src/libsystemd/sd-journal/test-journal-interleaving.c @@ -457,11 +457,11 @@ TEST(skip) { test_skip_one(setup_interleaved); } -static void test_boot_id_one(void (*setup)(void), size_t n_boots_expected) { +static void test_boot_id_one(void (*setup)(void), size_t n_ids_expected) { char t[] = "/var/tmp/journal-boot-id-XXXXXX"; _cleanup_(sd_journal_closep) sd_journal *j = NULL; - _cleanup_free_ BootId *boots = NULL; - size_t n_boots; + _cleanup_free_ LogId *ids = NULL; + size_t n_ids; mkdtemp_chdir_chattr(t); @@ -471,55 +471,55 @@ static void test_boot_id_one(void (*setup)(void), size_t n_boots_expected) { assert_se(journal_get_boots( j, /* advance_older = */ false, /* max_ids = */ SIZE_MAX, - &boots, &n_boots) >= 0); - assert_se(boots); - assert_se(n_boots == n_boots_expected); + &ids, &n_ids) >= 0); + assert_se(ids); + assert_se(n_ids == n_ids_expected); - for (size_t i = 0; i < n_boots; i++) { + for (size_t i = 0; i < n_ids; i++) { sd_id128_t id; /* positive offset */ assert_se(journal_find_boot(j, SD_ID128_NULL, (int) (i + 1), &id) == 1); - assert_se(sd_id128_equal(id, boots[i].id)); + assert_se(sd_id128_equal(id, ids[i].id)); /* negative offset */ - assert_se(journal_find_boot(j, SD_ID128_NULL, (int) (i + 1) - (int) n_boots, &id) == 1); - assert_se(sd_id128_equal(id, boots[i].id)); + assert_se(journal_find_boot(j, SD_ID128_NULL, (int) (i + 1) - (int) n_ids, &id) == 1); + assert_se(sd_id128_equal(id, ids[i].id)); - for (size_t k = 0; k < n_boots; k++) { + for (size_t k = 0; k < n_ids; k++) { int offset = (int) k - (int) i; /* relative offset */ - assert_se(journal_find_boot(j, boots[i].id, offset, &id) == 1); - assert_se(sd_id128_equal(id, boots[k].id)); + assert_se(journal_find_boot(j, ids[i].id, offset, &id) == 1); + assert_se(sd_id128_equal(id, ids[k].id)); } } - for (size_t i = 0; i <= n_boots_expected + 1; i++) { - _cleanup_free_ BootId *boots_limited = NULL; - size_t n_boots_limited; + for (size_t i = 0; i <= n_ids_expected + 1; i++) { + _cleanup_free_ LogId *ids_limited = NULL; + size_t n_ids_limited; assert_se(journal_get_boots( j, /* advance_older = */ false, /* max_ids = */ i, - &boots_limited, &n_boots_limited) >= 0); - assert_se(boots_limited || i == 0); - assert_se(n_boots_limited == MIN(i, n_boots_expected)); - assert_se(memcmp_safe(boots, boots_limited, n_boots_limited * sizeof(BootId)) == 0); + &ids_limited, &n_ids_limited) >= 0); + assert_se(ids_limited || i == 0); + assert_se(n_ids_limited == MIN(i, n_ids_expected)); + assert_se(memcmp_safe(ids, ids_limited, n_ids_limited * sizeof(LogId)) == 0); } - for (size_t i = 0; i <= n_boots_expected + 1; i++) { - _cleanup_free_ BootId *boots_limited = NULL; - size_t n_boots_limited; + for (size_t i = 0; i <= n_ids_expected + 1; i++) { + _cleanup_free_ LogId *ids_limited = NULL; + size_t n_ids_limited; assert_se(journal_get_boots( j, /* advance_older = */ true, /* max_ids = */ i, - &boots_limited, &n_boots_limited) >= 0); - assert_se(boots_limited || i == 0); - assert_se(n_boots_limited == MIN(i, n_boots_expected)); - for (size_t k = 0; k < n_boots_limited; k++) - assert_se(memcmp(&boots[n_boots - k - 1], &boots_limited[k], sizeof(BootId)) == 0); + &ids_limited, &n_ids_limited) >= 0); + assert_se(ids_limited || i == 0); + assert_se(n_ids_limited == MIN(i, n_ids_expected)); + for (size_t k = 0; k < n_ids_limited; k++) + assert_se(memcmp(&ids[n_ids - k - 1], &ids_limited[k], sizeof(LogId)) == 0); } test_done(t); diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 7dcc77e114..5dbe0d7727 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -1767,9 +1767,9 @@ int show_journal_by_unit( static int discover_next_boot( sd_journal *j, - sd_id128_t previous_boot_id, + sd_id128_t previous_id, bool advance_older, - BootId *ret) { + LogId *ret) { _cleanup_set_free_ Set *broken_ids = NULL; int r; @@ -1790,18 +1790,18 @@ static int discover_next_boot( for (;;) { sd_id128_t *id_dup; - BootId boot; + LogId id; r = sd_journal_step_one(j, !advance_older); if (r < 0) return r; if (r == 0) { sd_journal_flush_matches(j); - *ret = (BootId) {}; + *ret = (LogId) {}; return 0; /* End of journal, yay. */ } - r = sd_journal_get_monotonic_usec(j, NULL, &boot.id); + r = sd_journal_get_monotonic_usec(j, NULL, &id.id); if (r < 0) return r; @@ -1813,16 +1813,16 @@ static int discover_next_boot( * speed things up, but let's not trust that it is complete, and hence, manually advance as * necessary. */ - if (!sd_id128_is_null(previous_boot_id) && sd_id128_equal(boot.id, previous_boot_id)) + if (!sd_id128_is_null(previous_id) && sd_id128_equal(id.id, previous_id)) continue; - if (set_contains(broken_ids, &boot.id)) + if (set_contains(broken_ids, &id.id)) continue; /* Yay, we found a new boot ID from the entry object. Let's check there exist corresponding * entries matching with the _BOOT_ID= data. */ - r = add_match_boot_id(j, boot.id); + r = add_match_boot_id(j, id.id); if (r < 0) return r; @@ -1843,11 +1843,11 @@ static int discover_next_boot( if (r == 0) { log_debug("Whoopsie! We found a boot ID %s but can't read its first entry. " "The journal seems to be corrupted. Ignoring the boot ID.", - SD_ID128_TO_STRING(boot.id)); + SD_ID128_TO_STRING(id.id)); goto try_again; } - r = sd_journal_get_realtime_usec(j, advance_older ? &boot.last_usec : &boot.first_usec); + r = sd_journal_get_realtime_usec(j, advance_older ? &id.last_usec : &id.first_usec); if (r < 0) return r; @@ -1865,21 +1865,21 @@ static int discover_next_boot( if (r == 0) { log_debug("Whoopsie! We found a boot ID %s but can't read its last entry. " "The journal seems to be corrupted. Ignoring the boot ID.", - SD_ID128_TO_STRING(boot.id)); + SD_ID128_TO_STRING(id.id)); goto try_again; } - r = sd_journal_get_realtime_usec(j, advance_older ? &boot.first_usec : &boot.last_usec); + r = sd_journal_get_realtime_usec(j, advance_older ? &id.first_usec : &id.last_usec); if (r < 0) return r; sd_journal_flush_matches(j); - *ret = boot; + *ret = id; return 1; try_again: /* Save the bad boot ID. */ - id_dup = newdup(sd_id128_t, &boot.id, 1); + id_dup = newdup(sd_id128_t, &id.id, 1); if (!id_dup) return -ENOMEM; @@ -1890,8 +1890,8 @@ static int discover_next_boot( /* Move to the previous position again. */ sd_journal_flush_matches(j); - if (!sd_id128_is_null(previous_boot_id)) { - r = add_match_boot_id(j, previous_boot_id); + if (!sd_id128_is_null(previous_id)) { + r = add_match_boot_id(j, previous_id); if (r < 0) return r; } @@ -1909,7 +1909,7 @@ static int discover_next_boot( if (r == 0) return log_debug_errno(SYNTHETIC_ERRNO(ENODATA), "Whoopsie! Cannot seek to the last entry of boot %s.", - SD_ID128_TO_STRING(previous_boot_id)); + SD_ID128_TO_STRING(previous_id)); sd_journal_flush_matches(j); } @@ -1972,9 +1972,9 @@ int journal_find_boot(sd_journal *j, sd_id128_t boot_id, int offset, sd_id128_t * position us at the newest/oldest entry we have. */ for (int off = offset_start; ; off += advance_older ? -1 : 1) { - BootId boot; + LogId id; - r = discover_next_boot(j, boot_id, advance_older, &boot); + r = discover_next_boot(j, boot_id, advance_older, &id); if (r < 0) return r; if (r == 0) { @@ -1982,7 +1982,7 @@ int journal_find_boot(sd_journal *j, sd_id128_t boot_id, int offset, sd_id128_t return false; } - boot_id = boot.id; + boot_id = id.id; log_debug("Found boot ID %s by offset %i", SD_ID128_TO_STRING(boot_id), off); if (off == offset) { @@ -1996,16 +1996,16 @@ int journal_get_boots( sd_journal *j, bool advance_older, size_t max_ids, - BootId **ret_boots, - size_t *ret_n_boots) { + LogId **ret_ids, + size_t *ret_n_ids) { - _cleanup_free_ BootId *boots = NULL; - size_t n_boots = 0; + _cleanup_free_ LogId *ids = NULL; + size_t n_ids = 0; int r; assert(j); - assert(ret_boots); - assert(ret_n_boots); + assert(ret_ids); + assert(ret_n_ids); sd_journal_flush_matches(j); @@ -2021,33 +2021,33 @@ int journal_get_boots( * At this point the read pointer is positioned before the oldest entry in the whole journal. The * next invocation of _next() will hence position us at the oldest entry we have. */ - sd_id128_t previous_boot_id = SD_ID128_NULL; + sd_id128_t previous_id = SD_ID128_NULL; for (;;) { - BootId boot; + LogId id; - if (n_boots >= max_ids) + if (n_ids >= max_ids) break; - r = discover_next_boot(j, previous_boot_id, advance_older, &boot); + r = discover_next_boot(j, previous_id, advance_older, &id); if (r < 0) return r; if (r == 0) break; - previous_boot_id = boot.id; + previous_id = id.id; - FOREACH_ARRAY(i, boots, n_boots) - if (sd_id128_equal(i->id, boot.id)) + FOREACH_ARRAY(i, ids, n_ids) + if (sd_id128_equal(i->id, id.id)) /* The boot id is already stored, something wrong with the journal files. * Exiting as otherwise this problem would cause an infinite loop. */ goto finish; - if (!GREEDY_REALLOC_APPEND(boots, n_boots, &boot, 1)) + if (!GREEDY_REALLOC_APPEND(ids, n_ids, &id, 1)) return -ENOMEM; } finish: - *ret_boots = TAKE_PTR(boots); - *ret_n_boots = n_boots; - return n_boots > 0; + *ret_ids = TAKE_PTR(ids); + *ret_n_ids = n_ids; + return n_ids > 0; } diff --git a/src/shared/logs-show.h b/src/shared/logs-show.h index f775feb316..580855a00c 100644 --- a/src/shared/logs-show.h +++ b/src/shared/logs-show.h @@ -14,11 +14,11 @@ #include "set.h" #include "time-util.h" -typedef struct BootId { - sd_id128_t id; +typedef struct LogId { + sd_id128_t id; /* boot ID or invocation ID */ usec_t first_usec; usec_t last_usec; -} BootId; +} LogId; int show_journal_entry( FILE *f, @@ -76,5 +76,5 @@ int journal_get_boots( sd_journal *j, bool advance_older, size_t max_ids, - BootId **ret_boots, - size_t *ret_n_boots); + LogId **ret_ids, + size_t *ret_n_ids);