| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "journal-file.h" |
| 5 |
#include "list.h" |
| 6 |
#include "sd-forward.h" |
| 7 |
#include "time-util.h" |
| 8 |
|
| 9 |
#define JOURNAL_FILES_MAX 7168u |
| 10 |
|
| 11 |
#define JOURNAL_LOG_RATELIMIT ((const RateLimit) { .interval = 60 * USEC_PER_SEC, .burst = 3 }) |
| 12 |
|
| 13 |
typedef struct Match Match; |
| 14 |
typedef struct Location Location; |
| 15 |
typedef struct Directory Directory; |
| 16 |
|
| 17 |
typedef enum MatchType { |
| 18 |
MATCH_DISCRETE, |
| 19 |
MATCH_OR_TERM, |
| 20 |
MATCH_AND_TERM, |
| 21 |
} MatchType; |
| 22 |
|
| 23 |
typedef struct Match { |
| 24 |
MatchType type; |
| 25 |
Match *parent; |
| 26 |
LIST_FIELDS(Match, matches); |
| 27 |
|
| 28 |
/* For concrete matches */ |
| 29 |
char *data; |
| 30 |
size_t size; |
| 31 |
uint64_t hash; /* old-style jenkins hash. New-style siphash is different per file, hence won't be cached here */ |
| 32 |
|
| 33 |
/* For terms */ |
| 34 |
LIST_HEAD(Match, matches); |
| 35 |
} Match; |
| 36 |
|
| 37 |
typedef struct Location { |
| 38 |
LocationType type; |
| 39 |
|
| 40 |
bool seqnum_set:1; |
| 41 |
bool realtime_set:1; |
| 42 |
bool monotonic_set:1; |
| 43 |
bool xor_hash_set:1; |
| 44 |
|
| 45 |
uint64_t seqnum; |
| 46 |
sd_id128_t seqnum_id; |
| 47 |
|
| 48 |
uint64_t realtime; |
| 49 |
|
| 50 |
uint64_t monotonic; |
| 51 |
sd_id128_t boot_id; |
| 52 |
|
| 53 |
uint64_t xor_hash; |
| 54 |
} Location; |
| 55 |
|
| 56 |
typedef struct Directory { |
| 57 |
sd_journal *journal; |
| 58 |
char *path; |
| 59 |
int wd; |
| 60 |
bool is_root; |
| 61 |
unsigned last_seen_generation; |
| 62 |
} Directory; |
| 63 |
|
| 64 |
typedef struct NewestByBootId { |
| 65 |
sd_id128_t boot_id; |
| 66 |
Prioq *prioq; /* JournalFile objects ordered by monotonic timestamp of last update. */ |
| 67 |
} NewestByBootId; |
| 68 |
|
| 69 |
typedef struct sd_journal { |
| 70 |
int toplevel_fd; |
| 71 |
|
| 72 |
char *path; |
| 73 |
char *prefix; |
| 74 |
char *namespace; |
| 75 |
|
| 76 |
OrderedHashmap *files; |
| 77 |
IteratedCache *files_cache; |
| 78 |
MMapCache *mmap; |
| 79 |
|
| 80 |
/* a bisectable array of NewestByBootId, ordered by boot id. */ |
| 81 |
NewestByBootId *newest_by_boot_id; |
| 82 |
size_t n_newest_by_boot_id; |
| 83 |
|
| 84 |
Location current_location; |
| 85 |
|
| 86 |
JournalFile *current_file; |
| 87 |
uint64_t current_field; |
| 88 |
|
| 89 |
Match *level0, *level1, *level2; |
| 90 |
Set *exclude_syslog_identifiers; |
| 91 |
|
| 92 |
uint64_t origin_id; |
| 93 |
|
| 94 |
int inotify_fd; |
| 95 |
unsigned current_invalidate_counter, last_invalidate_counter; |
| 96 |
usec_t last_process_usec; |
| 97 |
unsigned generation; |
| 98 |
|
| 99 |
/* Iterating through unique fields and their data values */ |
| 100 |
char *unique_field; |
| 101 |
JournalFile *unique_file; |
| 102 |
uint64_t unique_offset; |
| 103 |
|
| 104 |
/* Iterating through known fields */ |
| 105 |
JournalFile *fields_file; |
| 106 |
uint64_t fields_offset; |
| 107 |
uint64_t fields_hash_table_index; |
| 108 |
char *fields_buffer; |
| 109 |
|
| 110 |
int flags; |
| 111 |
|
| 112 |
bool on_network:1; |
| 113 |
bool no_new_files:1; |
| 114 |
bool no_inotify:1; |
| 115 |
bool unique_file_lost:1; /* File we were iterating over got |
| 116 |
removed, and there were no more |
| 117 |
files, so sd_j_enumerate_unique |
| 118 |
will return a value equal to 0. */ |
| 119 |
bool fields_file_lost:1; |
| 120 |
bool has_runtime_files:1; |
| 121 |
bool has_persistent_files:1; |
| 122 |
|
| 123 |
size_t data_threshold; |
| 124 |
|
| 125 |
Hashmap *directories_by_path; |
| 126 |
Hashmap *directories_by_wd; |
| 127 |
|
| 128 |
Hashmap *errors; |
| 129 |
} sd_journal; |
| 130 |
|
| 131 |
char* journal_make_match_string(sd_journal *j); |
| 132 |
void journal_print_header(sd_journal *j); |
| 133 |
int journal_get_directories(sd_journal *j, char ***ret); |
| 134 |
|
| 135 |
int journal_add_match_pair(sd_journal *j, const char *field, const char *value); |
| 136 |
int journal_add_matchf(sd_journal *j, const char *format, ...) _printf_(2, 3); |
| 137 |
|
| 138 |
#define JOURNAL_FOREACH_DATA_RETVAL(j, data, l, retval) \ |
| 139 |
for (sd_journal_restart_data(j); ((retval) = sd_journal_enumerate_data((j), &(data), &(l))) > 0; ) |
| 140 |
|
| 141 |
/* All errors that we might encounter while extracting a field that are not real errors, |
| 142 |
* but only mean that the field is too large or we don't support the compression. */ |
| 143 |
static inline bool JOURNAL_ERRNO_IS_UNAVAILABLE_FIELD(int r) { |
| 144 |
return IN_SET(ABS(r), |
| 145 |
ENOBUFS, /* Field or decompressed field too large */ |
| 146 |
E2BIG, /* Field too large for pointer width */ |
| 147 |
EPROTONOSUPPORT); /* Unsupported compression */ |
| 148 |
} |