]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
c2f1db8f | 2 | #pragma once |
86aa7ba4 | 3 | |
86aa7ba4 | 4 | #include <stdbool.h> |
a8fbdf54 TA |
5 | #include <stddef.h> |
6 | #include <stdio.h> | |
1a6c43e9 | 7 | #include <sys/types.h> |
86aa7ba4 | 8 | |
c93d3c05 | 9 | #include "sd-id128.h" |
3c756001 | 10 | #include "sd-journal.h" |
81527be1 | 11 | |
a8fbdf54 | 12 | #include "macro.h" |
9bdbc2e2 | 13 | #include "output-mode.h" |
fad3feec | 14 | #include "rlimit-util.h" |
309a747f | 15 | #include "set.h" |
fad3feec | 16 | #include "sigbus.h" |
a8fbdf54 | 17 | #include "time-util.h" |
25277cd7 | 18 | |
6ecee6cf YW |
19 | typedef struct LogId { |
20 | sd_id128_t id; /* boot ID or invocation ID */ | |
8081939d YW |
21 | usec_t first_usec; |
22 | usec_t last_usec; | |
6ecee6cf | 23 | } LogId; |
8081939d | 24 | |
82721be7 YW |
25 | typedef enum LogIdType { |
26 | LOG_BOOT_ID, | |
27 | LOG_SYSTEM_UNIT_INVOCATION_ID, | |
28 | LOG_USER_UNIT_INVOCATION_ID, | |
29 | _LOG_ID_TYPE_MAX, | |
30 | _LOG_ID_TYPE_INVALID = -EINVAL, | |
31 | } LogIdType; | |
32 | ||
9b972c9a | 33 | int show_journal_entry( |
08ace05b LP |
34 | FILE *f, |
35 | sd_journal *j, | |
36 | OutputMode mode, | |
37 | unsigned n_columns, | |
94e0bd7d | 38 | OutputFlags flags, |
c5da14cd | 39 | Set *output_fields, |
05c7d9bf | 40 | const size_t highlight[2], |
893bcd3d | 41 | bool *ellipsized, |
4e30b87d | 42 | dual_timestamp *previous_display_ts, |
893bcd3d | 43 | sd_id128_t *previous_boot_id); |
889e3960 ZJS |
44 | int show_journal( |
45 | FILE *f, | |
46 | sd_journal *j, | |
47 | OutputMode mode, | |
48 | unsigned n_columns, | |
49 | usec_t not_before, | |
50 | unsigned how_many, | |
51 | OutputFlags flags, | |
52 | bool *ellipsized); | |
86aa7ba4 | 53 | |
c93d3c05 | 54 | int add_match_boot_id(sd_journal *j, sd_id128_t id); |
b6741478 | 55 | int add_match_this_boot(sd_journal *j, const char *machine); |
5ec76417 | 56 | |
1a997cb7 | 57 | int add_matches_for_invocation_id(sd_journal *j, sd_id128_t id); |
886a64fe | 58 | |
1a997cb7 YW |
59 | int add_matches_for_unit_full(sd_journal *j, bool all, const char *unit); |
60 | static inline int add_matches_for_unit(sd_journal *j, const char *unit) { | |
61 | return add_matches_for_unit_full(j, true, unit); | |
62 | } | |
63 | int add_matches_for_user_unit_full(sd_journal *j, bool all, const char *unit); | |
64 | static inline int add_matches_for_user_unit(sd_journal *j, const char *unit) { | |
65 | return add_matches_for_user_unit_full(j, true, unit); | |
66 | } | |
df50185b | 67 | |
886a64fe | 68 | int show_journal_by_unit( |
1a6c43e9 MT |
69 | FILE *f, |
70 | const char *unit, | |
d93dda3a | 71 | const char *namespace, |
1a6c43e9 MT |
72 | OutputMode mode, |
73 | unsigned n_columns, | |
74 | usec_t not_before, | |
75 | unsigned how_many, | |
886a64fe | 76 | OutputFlags flags, |
3c756001 LP |
77 | int journal_open_flags, |
78 | bool system_unit, | |
94e0bd7d | 79 | bool *ellipsized); |
1a6c43e9 | 80 | |
240a5fe8 LP |
81 | void json_escape( |
82 | FILE *f, | |
83 | const char* p, | |
84 | size_t l, | |
85 | OutputFlags flags); | |
8081939d | 86 | |
82721be7 YW |
87 | int journal_find_log_id( |
88 | sd_journal *j, | |
89 | LogIdType type, | |
90 | sd_id128_t boot_id, | |
91 | const char *unit, | |
92 | sd_id128_t id, | |
93 | int offset, | |
94 | sd_id128_t *ret); | |
95 | ||
96 | static inline int journal_find_boot( | |
97 | sd_journal *j, | |
98 | sd_id128_t id, | |
99 | int offset, | |
100 | sd_id128_t *ret) { | |
101 | ||
102 | return journal_find_log_id(j, LOG_BOOT_ID, | |
103 | /* boot_id = */ SD_ID128_NULL, /* unit = */ NULL, | |
104 | id, offset, ret); | |
105 | } | |
106 | ||
107 | int journal_get_log_ids( | |
d0936a72 | 108 | sd_journal *j, |
82721be7 YW |
109 | LogIdType type, |
110 | sd_id128_t boot_id, | |
111 | const char *unit, | |
d0936a72 YW |
112 | bool advance_older, |
113 | size_t max_ids, | |
6ecee6cf YW |
114 | LogId **ret_ids, |
115 | size_t *ret_n_ids); | |
82721be7 YW |
116 | |
117 | static inline int journal_get_boots( | |
118 | sd_journal *j, | |
119 | bool advance_older, | |
120 | size_t max_ids, | |
121 | LogId **ret_ids, | |
122 | size_t *ret_n_ids) { | |
123 | ||
124 | return journal_get_log_ids(j, LOG_BOOT_ID, | |
125 | /* boot_id = */ SD_ID128_NULL, /* unit = */ NULL, | |
126 | advance_older, max_ids, | |
127 | ret_ids, ret_n_ids); | |
128 | } | |
fad3feec MY |
129 | |
130 | static inline void journal_browse_prepare(void) { | |
131 | /* Increase max number of open files if we can, we might needs this when browsing journal files, | |
132 | * which might be split up into many files. */ | |
133 | (void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE); | |
134 | ||
135 | sigbus_install(); | |
136 | } |