X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;ds=sidebyside;f=src%2Fshared%2Flogs-show.c;h=79a977c156e6c675fbc948d2860169af8d40a2ad;hb=5ec76417764e19486261fb8e38e8e71b28185b37;hp=43386841bafba8b95360969e0ac100f57a1104d8;hpb=886a64fe6903bc1ccde5c7af0eac6786918c8e49;p=elogind.git diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 43386841b..79a977c15 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -30,6 +30,7 @@ #include "util.h" #include "utf8.h" #include "hashmap.h" +#include "journal-internal.h" #define PRINT_THRESHOLD 128 #define JSON_THRESHOLD 4096 @@ -277,7 +278,7 @@ static int output_short( } else if ((flags & OUTPUT_FULL_WIDTH) || (message_len + n + 1 < n_columns)) fprintf(f, ": %s%.*s%s\n", color_on, (int) message_len, message, color_off); else if (n < n_columns && n_columns - n - 2 >= 3) { - char _cleanup_free_ *e; + _cleanup_free_ char *e; e = ellipsize_mem(message, message_len, n_columns - n - 2, 90); @@ -303,7 +304,7 @@ static int output_verbose( const void *data; size_t length; - char _cleanup_free_ *cursor = NULL; + _cleanup_free_ char *cursor = NULL; uint64_t realtime; char ts[FORMAT_TIMESTAMP_MAX]; int r; @@ -365,7 +366,7 @@ static int output_export( char sid[33]; int r; usec_t realtime, monotonic; - char _cleanup_free_ *cursor = NULL; + _cleanup_free_ char *cursor = NULL; const void *data; size_t length; @@ -494,7 +495,7 @@ static int output_json( OutputFlags flags) { uint64_t realtime, monotonic; - char _cleanup_free_ *cursor = NULL; + _cleanup_free_ char *cursor = NULL; const void *data; size_t length; sd_id128_t boot_id; @@ -930,6 +931,33 @@ int add_matches_for_user_unit(sd_journal *j, const char *unit, uid_t uid) { return r; } +int add_match_this_boot(sd_journal *j) { + char match[9+32+1] = "_BOOT_ID="; + sd_id128_t boot_id; + int r; + + assert(j); + + r = sd_id128_get_boot(&boot_id); + if (r < 0) { + log_error("Failed to get boot id: %s", strerror(-r)); + return r; + } + + sd_id128_to_string(boot_id, match + 9); + r = sd_journal_add_match(j, match, strlen(match)); + if (r < 0) { + log_error("Failed to add match: %s", strerror(-r)); + return r; + } + + r = sd_journal_add_conjunction(j); + if (r < 0) + return r; + + return 0; +} + int show_journal_by_unit( FILE *f, const char *unit, @@ -941,7 +969,7 @@ int show_journal_by_unit( OutputFlags flags, bool system) { - sd_journal *j = NULL; + _cleanup_journal_close_ sd_journal*j = NULL; int r; int jflags = SD_JOURNAL_LOCAL_ONLY | system * SD_JOURNAL_SYSTEM_ONLY; @@ -954,24 +982,26 @@ int show_journal_by_unit( r = sd_journal_open(&j, jflags); if (r < 0) - goto finish; + return r; + + r = add_match_this_boot(j); + if (r < 0) + return r; if (system) r = add_matches_for_unit(j, unit); else r = add_matches_for_user_unit(j, unit, uid); if (r < 0) - goto finish; + return r; + + log_debug("Journal filter: %s", journal_make_match_string(j)); r = show_journal(f, j, mode, n_columns, not_before, how_many, flags); if (r < 0) - goto finish; - -finish: - if (j) - sd_journal_close(j); + return r; - return r; + return 0; } static const char *const output_mode_table[_OUTPUT_MODE_MAX] = {