Debian Codegraph @

src/shared/logs-show.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "sd-id128.h"
5
6 #include "shared-forward.h"
7
8 typedef struct LogId {
9 sd_id128_t id; /* boot ID or invocation ID */
10 usec_t first_usec;
11 usec_t last_usec;
12 } LogId;
13
14 typedef enum LogIdType {
15 LOG_BOOT_ID,
16 LOG_SYSTEM_UNIT_INVOCATION_ID,
17 LOG_USER_UNIT_INVOCATION_ID,
18 _LOG_ID_TYPE_MAX,
19 _LOG_ID_TYPE_INVALID = -EINVAL,
20 } LogIdType;
21
22 int show_journal_entry(
23 FILE *f,
24 sd_journal *j,
25 OutputMode mode,
26 unsigned n_columns,
27 OutputFlags flags,
28 Set *output_fields,
29 const size_t highlight[2],
30 bool *ellipsized,
31 dual_timestamp *previous_display_ts,
32 sd_id128_t *previous_boot_id);
33 int show_journal(
34 FILE *f,
35 sd_journal *j,
36 OutputMode mode,
37 unsigned n_columns,
38 usec_t not_before,
39 unsigned how_many,
40 OutputFlags flags,
41 bool *ellipsized);
42
43 int add_match_boot_id(sd_journal *j, sd_id128_t id);
44 int add_match_this_boot(sd_journal *j, const char *machine);
45
46 int add_matches_for_invocation_id(sd_journal *j, sd_id128_t id);
47
48 typedef enum MatchUnitFlag {
49 MATCH_UNIT_SLICE = 1 << 0,
50 MATCH_UNIT_COREDUMP = 1 << 1,
51 MATCH_UNIT_COREDUMP_UID = 1 << 2,
52
53 MATCH_UNIT_ALL = MATCH_UNIT_SLICE | MATCH_UNIT_COREDUMP | MATCH_UNIT_COREDUMP_UID,
54 } MatchUnitFlag;
55
56 int add_matches_for_unit_full(sd_journal *j, MatchUnitFlag flags, const char *unit);
57 static inline int add_matches_for_unit(sd_journal *j, const char *unit) {
58 return add_matches_for_unit_full(j, MATCH_UNIT_ALL, unit);
59 }
60 int add_matches_for_user_unit_full(sd_journal *j, MatchUnitFlag flags, uid_t uid, const char *unit);
61 static inline int add_matches_for_user_unit(sd_journal *j, const char *unit) {
62 return add_matches_for_user_unit_full(j, MATCH_UNIT_ALL, UID_INVALID, unit);
63 }
64
65 int show_journal_by_unit(
66 FILE *f,
67 const char *unit,
68 const char *namespace,
69 OutputMode mode,
70 unsigned n_columns,
71 usec_t not_before,
72 unsigned how_many,
73 OutputFlags flags,
74 int journal_open_flags,
75 bool system_unit,
76 bool *ellipsized);
77
78 void json_escape(
79 FILE *f,
80 const char* p,
81 size_t l,
82 OutputFlags flags);
83
84 int journal_entry_to_json(sd_journal *j, OutputFlags flags, const Set *output_fields, sd_json_variant **ret);
85
86 int discover_next_id(
87 sd_journal *j,
88 LogIdType type,
89 sd_id128_t boot_id, /* optional, used when type == JOURNAL_{SYSTEM,USER}_UNIT_INVOCATION_ID */
90 const char *unit, /* mandatory when type == JOURNAL_{SYSTEM,USER}_UNIT_INVOCATION_ID */
91 sd_id128_t previous_id,
92 bool advance_older,
93 LogId *ret);
94
95 int journal_find_log_id(
96 sd_journal *j,
97 LogIdType type,
98 sd_id128_t boot_id,
99 const char *unit,
100 sd_id128_t id,
101 int offset,
102 sd_id128_t *ret);
103
104 static inline int journal_find_boot(
105 sd_journal *j,
106 sd_id128_t id,
107 int offset,
108 sd_id128_t *ret) {
109
110 return journal_find_log_id(j, LOG_BOOT_ID,
111 /* boot_id= */ SD_ID128_NULL, /* unit= */ NULL,
112 id, offset, ret);
113 }
114
115 int journal_get_log_ids(
116 sd_journal *j,
117 LogIdType type,
118 sd_id128_t boot_id,
119 const char *unit,
120 bool advance_older,
121 size_t max_ids,
122 LogId **ret_ids,
123 size_t *ret_n_ids);
124
125 static inline int journal_get_boots(
126 sd_journal *j,
127 bool advance_older,
128 size_t max_ids,
129 LogId **ret_ids,
130 size_t *ret_n_ids) {
131
132 return journal_get_log_ids(j, LOG_BOOT_ID,
133 /* boot_id= */ SD_ID128_NULL, /* unit= */ NULL,
134 advance_older, max_ids,
135 ret_ids, ret_n_ids);
136 }
137
138 void journal_browse_prepare(void);