#include "journal-internal.h"
#include "journalctl.h"
#include "journalctl-filter.h"
+#include "journalctl-util.h"
#include "logs-show.h"
#include "missing_sched.h"
#include "nulstr-util.h"
if (!arg_boot)
return 0;
- /* Take a shortcut and use the current boot_id, which we can do very quickly.
- * We can do this only when we logs are coming from the current machine,
- * so take the slow path if log location is specified. */
- if (arg_boot_offset == 0 && sd_id128_is_null(arg_boot_id) &&
- !arg_directory && !arg_file && !arg_root)
- return add_match_this_boot(j, arg_machine);
-
- if (sd_id128_is_null(arg_boot_id)) {
- r = journal_find_boot_by_offset(j, arg_boot_offset, &arg_boot_id);
- if (r < 0)
- return log_error_errno(r, "Failed to find journal entry from the specified boot offset (%+i): %m",
- arg_boot_offset);
- if (r == 0)
- return log_error_errno(SYNTHETIC_ERRNO(ENODATA),
- "No journal boot entry found from the specified boot offset (%+i).",
- arg_boot_offset);
- } else {
- r = journal_find_boot_by_id(j, arg_boot_id);
- if (r < 0)
- return log_error_errno(r, "Failed to find journal entry from the specified boot ID (%s): %m",
- SD_ID128_TO_STRING(arg_boot_id));
- if (r == 0)
- return log_error_errno(SYNTHETIC_ERRNO(ENODATA),
- "No journal boot entry found from the specified boot ID (%s).",
- SD_ID128_TO_STRING(arg_boot_id));
- }
+ assert(!sd_id128_is_null(arg_boot_id));
r = add_match_boot_id(j, arg_boot_id);
if (r < 0)
- return log_error_errno(r, "Failed to add match: %m");
-
- r = sd_journal_add_conjunction(j);
- if (r < 0)
- return log_error_errno(r, "Failed to add conjunction: %m");
+ return r;
- return 0;
+ return sd_journal_add_conjunction(j);
}
static int add_dmesg(sd_journal *j) {
assert(j);
- /* add_boot() must be called first!
- * It may need to seek the journal to find parent boot IDs. */
- r = add_boot(j);
+ /* First, search boot ID, as that may set and flush matches and seek journal. */
+ r = journal_acquire_boot(j);
if (r < 0)
return r;
+ /* Clear unexpected matches for safety. */
+ sd_journal_flush_matches(j);
+
+ /* Then, add filters in the below. */
+ r = add_boot(j);
+ if (r < 0)
+ return log_error_errno(r, "Failed to add filter for boot: %m");
+
r = add_dmesg(j);
if (r < 0)
return log_error_errno(r, "Failed to add filter for dmesg: %m");
#include <unistd.h>
+#include "id128-util.h"
#include "journal-util.h"
#include "journalctl.h"
#include "journalctl-util.h"
+#include "logs-show.h"
#include "rlimit-util.h"
#include "sigbus.h"
#include "terminal-util.h"
return true;
}
+
+int journal_acquire_boot(sd_journal *j) {
+ int r;
+
+ assert(j);
+
+ if (!arg_boot) {
+ /* Clear relevant field for safety. */
+ arg_boot_id = SD_ID128_NULL;
+ arg_boot_offset = 0;
+ return 0;
+ }
+
+ /* Take a shortcut and use the current boot_id, which we can do very quickly.
+ * We can do this only when the logs are coming from the current machine,
+ * so take the slow path if log location is specified. */
+ if (arg_boot_offset == 0 && sd_id128_is_null(arg_boot_id) &&
+ !arg_directory && !arg_file && !arg_root) {
+ r = id128_get_boot_for_machine(arg_machine, &arg_boot_id);
+ if (r < 0)
+ return log_error_errno(r, "Failed to get boot ID%s%s: %m",
+ isempty(arg_machine) ? "" : " of container ", strempty(arg_machine));
+ } else if (sd_id128_is_null(arg_boot_id)) {
+ r = journal_find_boot_by_offset(j, arg_boot_offset, &arg_boot_id);
+ if (r < 0)
+ return log_error_errno(r, "Failed to find journal entry from the specified boot offset (%+i): %m",
+ arg_boot_offset);
+ if (r == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(ENODATA),
+ "No journal boot entry found from the specified boot offset (%+i).",
+ arg_boot_offset);
+ } else {
+ r = journal_find_boot_by_id(j, arg_boot_id);
+ if (r < 0)
+ return log_error_errno(r, "Failed to find journal entry from the specified boot ID (%s): %m",
+ SD_ID128_TO_STRING(arg_boot_id));
+ if (r == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(ENODATA),
+ "No journal boot entry found from the specified boot ID (%s).",
+ SD_ID128_TO_STRING(arg_boot_id));
+ }
+
+ return 1;
+}