Line data Source code
1 : /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2 :
3 : #pragma once
4 :
5 : /***
6 : This file is part of systemd.
7 :
8 : Copyright 2011 Lennart Poettering
9 :
10 : systemd is free software; you can redistribute it and/or modify it
11 : under the terms of the GNU Lesser General Public License as published by
12 : the Free Software Foundation; either version 2.1 of the License, or
13 : (at your option) any later version.
14 :
15 : systemd is distributed in the hope that it will be useful, but
16 : WITHOUT ANY WARRANTY; without even the implied warranty of
17 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 : Lesser General Public License for more details.
19 :
20 : You should have received a copy of the GNU Lesser General Public License
21 : along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 : ***/
23 :
24 : #include <sys/types.h>
25 : #include <inttypes.h>
26 : #include <stdbool.h>
27 :
28 : #include "systemd/sd-id128.h"
29 :
30 : #include "journal-def.h"
31 : #include "list.h"
32 : #include "hashmap.h"
33 : #include "set.h"
34 : #include "journal-file.h"
35 : #include "sd-journal.h"
36 :
37 : typedef struct Match Match;
38 : typedef struct Location Location;
39 : typedef struct Directory Directory;
40 :
41 : typedef enum MatchType {
42 : MATCH_DISCRETE,
43 : MATCH_OR_TERM,
44 : MATCH_AND_TERM
45 : } MatchType;
46 :
47 : struct Match {
48 : MatchType type;
49 : Match *parent;
50 : LIST_FIELDS(Match, matches);
51 :
52 : /* For concrete matches */
53 : char *data;
54 : size_t size;
55 : le64_t le_hash;
56 :
57 : /* For terms */
58 : LIST_HEAD(Match, matches);
59 : };
60 :
61 : struct Location {
62 : LocationType type;
63 :
64 : bool seqnum_set;
65 : bool realtime_set;
66 : bool monotonic_set;
67 : bool xor_hash_set;
68 :
69 : uint64_t seqnum;
70 : sd_id128_t seqnum_id;
71 :
72 : uint64_t realtime;
73 :
74 : uint64_t monotonic;
75 : sd_id128_t boot_id;
76 :
77 : uint64_t xor_hash;
78 : };
79 :
80 : struct Directory {
81 : char *path;
82 : int wd;
83 : bool is_root;
84 : };
85 :
86 : struct sd_journal {
87 : char *path;
88 : char *prefix;
89 :
90 : OrderedHashmap *files;
91 : MMapCache *mmap;
92 :
93 : Location current_location;
94 :
95 : JournalFile *current_file;
96 : uint64_t current_field;
97 :
98 : Match *level0, *level1, *level2;
99 :
100 : pid_t original_pid;
101 :
102 : int inotify_fd;
103 : unsigned current_invalidate_counter, last_invalidate_counter;
104 : usec_t last_process_usec;
105 :
106 : char *unique_field;
107 : JournalFile *unique_file;
108 : uint64_t unique_offset;
109 :
110 : int flags;
111 :
112 : bool on_network;
113 : bool no_new_files;
114 : bool unique_file_lost; /* File we were iterating over got
115 : removed, and there were no more
116 : files, so sd_j_enumerate_unique
117 : will return a value equal to 0. */
118 :
119 : size_t data_threshold;
120 :
121 : Hashmap *directories_by_path;
122 : Hashmap *directories_by_wd;
123 :
124 : Set *errors;
125 : };
126 :
127 : char *journal_make_match_string(sd_journal *j);
128 : void journal_print_header(sd_journal *j);
129 :
130 2 : DEFINE_TRIVIAL_CLEANUP_FUNC(sd_journal*, sd_journal_close);
131 : #define _cleanup_journal_close_ _cleanup_(sd_journal_closep)
132 :
133 : #define JOURNAL_FOREACH_DATA_RETVAL(j, data, l, retval) \
134 : for (sd_journal_restart_data(j); ((retval) = sd_journal_enumerate_data((j), &(data), &(l))) > 0; )
|