]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
c2f1db8f | 2 | #pragma once |
f39e126e LP |
3 | |
4 | /*** | |
f39e126e | 5 | Copyright 2011 Lennart Poettering |
f39e126e LP |
6 | ***/ |
7 | ||
f39e126e LP |
8 | #include <inttypes.h> |
9 | #include <stdbool.h> | |
71d35b6b | 10 | #include <sys/types.h> |
f39e126e | 11 | |
07630cea LP |
12 | #include "sd-id128.h" |
13 | #include "sd-journal.h" | |
81527be1 | 14 | |
07630cea | 15 | #include "hashmap.h" |
cbdca852 | 16 | #include "journal-def.h" |
07630cea | 17 | #include "journal-file.h" |
f39e126e | 18 | #include "list.h" |
6fe391c5 | 19 | #include "set.h" |
cbdca852 | 20 | |
f39e126e | 21 | typedef struct Match Match; |
a963990f LP |
22 | typedef struct Location Location; |
23 | typedef struct Directory Directory; | |
24 | ||
cbdca852 LP |
25 | typedef enum MatchType { |
26 | MATCH_DISCRETE, | |
27 | MATCH_OR_TERM, | |
28 | MATCH_AND_TERM | |
29 | } MatchType; | |
f39e126e LP |
30 | |
31 | struct Match { | |
cbdca852 LP |
32 | MatchType type; |
33 | Match *parent; | |
34 | LIST_FIELDS(Match, matches); | |
35 | ||
36 | /* For concrete matches */ | |
f39e126e LP |
37 | char *data; |
38 | size_t size; | |
4fd052ae | 39 | le64_t le_hash; |
f39e126e | 40 | |
cbdca852 LP |
41 | /* For terms */ |
42 | LIST_HEAD(Match, matches); | |
f39e126e LP |
43 | }; |
44 | ||
a963990f | 45 | struct Location { |
cbdca852 | 46 | LocationType type; |
f39e126e | 47 | |
68667801 ZJS |
48 | bool seqnum_set; |
49 | bool realtime_set; | |
50 | bool monotonic_set; | |
51 | bool xor_hash_set; | |
52 | ||
f39e126e LP |
53 | uint64_t seqnum; |
54 | sd_id128_t seqnum_id; | |
f39e126e LP |
55 | |
56 | uint64_t realtime; | |
f39e126e LP |
57 | |
58 | uint64_t monotonic; | |
59 | sd_id128_t boot_id; | |
f39e126e LP |
60 | |
61 | uint64_t xor_hash; | |
a963990f LP |
62 | }; |
63 | ||
64 | struct Directory { | |
65 | char *path; | |
66 | int wd; | |
67 | bool is_root; | |
858749f7 | 68 | unsigned last_seen_generation; |
a963990f | 69 | }; |
f39e126e LP |
70 | |
71 | struct sd_journal { | |
5d1ce257 LP |
72 | int toplevel_fd; |
73 | ||
7827b1a1 | 74 | char *path; |
89739579 | 75 | char *prefix; |
7827b1a1 | 76 | |
c1f906bd | 77 | OrderedHashmap *files; |
5d4ba7f2 | 78 | IteratedCache *files_cache; |
16e9f408 | 79 | MMapCache *mmap; |
f39e126e LP |
80 | |
81 | Location current_location; | |
cbdca852 | 82 | |
f39e126e LP |
83 | JournalFile *current_file; |
84 | uint64_t current_field; | |
85 | ||
cd34b3c6 | 86 | Match *level0, *level1, *level2; |
a963990f | 87 | |
a65f06bb ZJS |
88 | pid_t original_pid; |
89 | ||
90 | int inotify_fd; | |
a963990f | 91 | unsigned current_invalidate_counter, last_invalidate_counter; |
a65f06bb | 92 | usec_t last_process_usec; |
858749f7 | 93 | unsigned generation; |
3c1668da | 94 | |
eb86030e | 95 | /* Iterating through unique fields and their data values */ |
3c1668da LP |
96 | char *unique_field; |
97 | JournalFile *unique_file; | |
98 | uint64_t unique_offset; | |
85210bff | 99 | |
eb86030e LP |
100 | /* Iterating through known fields */ |
101 | JournalFile *fields_file; | |
102 | uint64_t fields_offset; | |
103 | uint64_t fields_hash_table_index; | |
104 | char *fields_buffer; | |
105 | size_t fields_buffer_allocated; | |
106 | ||
a65f06bb ZJS |
107 | int flags; |
108 | ||
eb86030e LP |
109 | bool on_network:1; |
110 | bool no_new_files:1; | |
5d1ce257 | 111 | bool no_inotify:1; |
eb86030e LP |
112 | bool unique_file_lost:1; /* File we were iterating over got |
113 | removed, and there were no more | |
114 | files, so sd_j_enumerate_unique | |
115 | will return a value equal to 0. */ | |
116 | bool fields_file_lost:1; | |
39fd5b08 JS |
117 | bool has_runtime_files:1; |
118 | bool has_persistent_files:1; | |
93b73b06 LP |
119 | |
120 | size_t data_threshold; | |
6fe391c5 | 121 | |
a65f06bb ZJS |
122 | Hashmap *directories_by_path; |
123 | Hashmap *directories_by_wd; | |
39c155ea | 124 | |
5768d259 | 125 | Hashmap *errors; |
f39e126e LP |
126 | }; |
127 | ||
cbdca852 | 128 | char *journal_make_match_string(sd_journal *j); |
dca6219e | 129 | void journal_print_header(sd_journal *j); |
dfb33a97 | 130 | |
a72b6353 ZJS |
131 | #define JOURNAL_FOREACH_DATA_RETVAL(j, data, l, retval) \ |
132 | for (sd_journal_restart_data(j); ((retval) = sd_journal_enumerate_data((j), &(data), &(l))) > 0; ) |