]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/journal-internal.h
8f1d35aec546416158c684bd3da54c0ca6d4b26e
[thirdparty/systemd.git] / src / journal / journal-internal.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 Copyright 2011 Lennart Poettering
6 ***/
7
8 #include <inttypes.h>
9 #include <stdbool.h>
10 #include <sys/types.h>
11
12 #include "sd-id128.h"
13 #include "sd-journal.h"
14
15 #include "hashmap.h"
16 #include "journal-def.h"
17 #include "journal-file.h"
18 #include "list.h"
19 #include "set.h"
20
21 typedef struct Match Match;
22 typedef struct Location Location;
23 typedef struct Directory Directory;
24
25 typedef enum MatchType {
26 MATCH_DISCRETE,
27 MATCH_OR_TERM,
28 MATCH_AND_TERM
29 } MatchType;
30
31 struct Match {
32 MatchType type;
33 Match *parent;
34 LIST_FIELDS(Match, matches);
35
36 /* For concrete matches */
37 char *data;
38 size_t size;
39 le64_t le_hash;
40
41 /* For terms */
42 LIST_HEAD(Match, matches);
43 };
44
45 struct Location {
46 LocationType type;
47
48 bool seqnum_set;
49 bool realtime_set;
50 bool monotonic_set;
51 bool xor_hash_set;
52
53 uint64_t seqnum;
54 sd_id128_t seqnum_id;
55
56 uint64_t realtime;
57
58 uint64_t monotonic;
59 sd_id128_t boot_id;
60
61 uint64_t xor_hash;
62 };
63
64 struct Directory {
65 char *path;
66 int wd;
67 bool is_root;
68 unsigned last_seen_generation;
69 };
70
71 struct sd_journal {
72 int toplevel_fd;
73
74 char *path;
75 char *prefix;
76
77 OrderedHashmap *files;
78 IteratedCache *files_cache;
79 MMapCache *mmap;
80
81 Location current_location;
82
83 JournalFile *current_file;
84 uint64_t current_field;
85
86 Match *level0, *level1, *level2;
87
88 pid_t original_pid;
89
90 int inotify_fd;
91 unsigned current_invalidate_counter, last_invalidate_counter;
92 usec_t last_process_usec;
93 unsigned generation;
94
95 /* Iterating through unique fields and their data values */
96 char *unique_field;
97 JournalFile *unique_file;
98 uint64_t unique_offset;
99
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
107 int flags;
108
109 bool on_network:1;
110 bool no_new_files:1;
111 bool no_inotify:1;
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;
117 bool has_runtime_files:1;
118 bool has_persistent_files:1;
119
120 size_t data_threshold;
121
122 Hashmap *directories_by_path;
123 Hashmap *directories_by_wd;
124
125 Hashmap *errors;
126 };
127
128 char *journal_make_match_string(sd_journal *j);
129 void journal_print_header(sd_journal *j);
130
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; )