]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journalctl: split out show_log_ids() from action_list_boots()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 25 Apr 2024 04:15:49 +0000 (13:15 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 31 Jul 2024 22:31:44 +0000 (07:31 +0900)
No functional change, just refactoring and prepraration for later change.

src/journal/journalctl-misc.c

index 880a0900ebf4d907302f43e3bc8ba2062eeecda9..bc063d930bc5ffa6b5129ab69267e04a159ee41c 100644 (file)
@@ -98,31 +98,15 @@ int action_disk_usage(void) {
         return 0;
 }
 
-int action_list_boots(void) {
-        _cleanup_(sd_journal_closep) sd_journal *j = NULL;
+static int show_log_ids(const LogId *ids, size_t n_ids, const char *name) {
         _cleanup_(table_unrefp) Table *table = NULL;
-        _cleanup_free_ LogId *ids = NULL;
-        size_t n_ids;
         int r;
 
-        assert(arg_action == ACTION_LIST_BOOTS);
-
-        r = acquire_journal(&j);
-        if (r < 0)
-                return r;
+        assert(ids);
+        assert(n_ids > 0);
+        assert(name);
 
-        r = journal_get_boots(
-                        j,
-                        /* advance_older = */ arg_lines_needs_seek_end(),
-                        /* max_ids = */ arg_lines >= 0 ? (size_t) arg_lines : SIZE_MAX,
-                        &ids, &n_ids);
-        if (r < 0)
-                return log_error_errno(r, "Failed to determine boots: %m");
-        if (r == 0)
-                return log_full_errno(arg_quiet ? LOG_DEBUG : LOG_ERR, SYNTHETIC_ERRNO(ENODATA),
-                                      "No boot found.");
-
-        table = table_new("idx", "boot id", "first entry", "last entry");
+        table = table_new("idx", name, "first entry", "last entry");
         if (!table)
                 return log_oom();
 
@@ -166,6 +150,32 @@ int action_list_boots(void) {
         return 0;
 }
 
+int action_list_boots(void) {
+        _cleanup_(sd_journal_closep) sd_journal *j = NULL;
+        _cleanup_free_ LogId *ids = NULL;
+        size_t n_ids;
+        int r;
+
+        assert(arg_action == ACTION_LIST_BOOTS);
+
+        r = acquire_journal(&j);
+        if (r < 0)
+                return r;
+
+        r = journal_get_boots(
+                        j,
+                        /* advance_older = */ arg_lines_needs_seek_end(),
+                        /* max_ids = */ arg_lines >= 0 ? (size_t) arg_lines : SIZE_MAX,
+                        &ids, &n_ids);
+        if (r < 0)
+                return log_error_errno(r, "Failed to determine boots: %m");
+        if (r == 0)
+                return log_full_errno(arg_quiet ? LOG_DEBUG : LOG_ERR, SYNTHETIC_ERRNO(ENODATA),
+                                      "No boot found.");
+
+        return show_log_ids(ids, n_ids, "boot id");
+}
+
 int action_list_fields(void) {
         _cleanup_(sd_journal_closep) sd_journal *j = NULL;
         int r, n_shown = 0;