2012-07-18 19:07:51 +02:00
|
|
|
#pragma once
|
2011-12-30 16:01:33 +01:00
|
|
|
|
|
|
|
/***
|
|
|
|
This file is part of systemd.
|
|
|
|
|
|
|
|
Copyright 2011 Lennart Poettering
|
|
|
|
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
2012-04-12 00:20:58 +02:00
|
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
2011-12-30 16:01:33 +01:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
systemd is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2012-04-12 00:20:58 +02:00
|
|
|
Lesser General Public License for more details.
|
2011-12-30 16:01:33 +01:00
|
|
|
|
2012-04-12 00:20:58 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2011-12-30 16:01:33 +01:00
|
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
***/
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdbool.h>
|
2015-11-18 22:46:33 +01:00
|
|
|
#include <sys/types.h>
|
2011-12-30 16:01:33 +01:00
|
|
|
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "sd-id128.h"
|
|
|
|
#include "sd-journal.h"
|
2012-01-05 16:01:58 +01:00
|
|
|
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "hashmap.h"
|
2012-07-13 00:29:26 +02:00
|
|
|
#include "journal-def.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "journal-file.h"
|
2011-12-30 16:01:33 +01:00
|
|
|
#include "list.h"
|
2013-03-11 23:03:13 +01:00
|
|
|
#include "set.h"
|
2012-07-13 00:29:26 +02:00
|
|
|
|
2011-12-30 16:01:33 +01:00
|
|
|
typedef struct Match Match;
|
2012-07-11 01:08:38 +02:00
|
|
|
typedef struct Location Location;
|
|
|
|
typedef struct Directory Directory;
|
|
|
|
|
2012-07-13 00:29:26 +02:00
|
|
|
typedef enum MatchType {
|
|
|
|
MATCH_DISCRETE,
|
|
|
|
MATCH_OR_TERM,
|
|
|
|
MATCH_AND_TERM
|
|
|
|
} MatchType;
|
2011-12-30 16:01:33 +01:00
|
|
|
|
|
|
|
struct Match {
|
2012-07-13 00:29:26 +02:00
|
|
|
MatchType type;
|
|
|
|
Match *parent;
|
|
|
|
LIST_FIELDS(Match, matches);
|
|
|
|
|
|
|
|
/* For concrete matches */
|
2011-12-30 16:01:33 +01:00
|
|
|
char *data;
|
|
|
|
size_t size;
|
2012-03-16 11:59:04 +01:00
|
|
|
le64_t le_hash;
|
2011-12-30 16:01:33 +01:00
|
|
|
|
2012-07-13 00:29:26 +02:00
|
|
|
/* For terms */
|
|
|
|
LIST_HEAD(Match, matches);
|
2011-12-30 16:01:33 +01:00
|
|
|
};
|
|
|
|
|
2012-07-11 01:08:38 +02:00
|
|
|
struct Location {
|
2012-07-13 00:29:26 +02:00
|
|
|
LocationType type;
|
2011-12-30 16:01:33 +01:00
|
|
|
|
2013-05-08 03:07:39 +02:00
|
|
|
bool seqnum_set;
|
|
|
|
bool realtime_set;
|
|
|
|
bool monotonic_set;
|
|
|
|
bool xor_hash_set;
|
|
|
|
|
2011-12-30 16:01:33 +01:00
|
|
|
uint64_t seqnum;
|
|
|
|
sd_id128_t seqnum_id;
|
|
|
|
|
|
|
|
uint64_t realtime;
|
|
|
|
|
|
|
|
uint64_t monotonic;
|
|
|
|
sd_id128_t boot_id;
|
|
|
|
|
|
|
|
uint64_t xor_hash;
|
2012-07-11 01:08:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Directory {
|
|
|
|
char *path;
|
|
|
|
int wd;
|
|
|
|
bool is_root;
|
|
|
|
};
|
2011-12-30 16:01:33 +01:00
|
|
|
|
|
|
|
struct sd_journal {
|
2016-04-25 00:31:24 +02:00
|
|
|
int toplevel_fd;
|
|
|
|
|
2012-07-19 03:21:49 +02:00
|
|
|
char *path;
|
2013-12-11 23:10:36 +01:00
|
|
|
char *prefix;
|
2012-07-19 03:21:49 +02:00
|
|
|
|
2014-08-19 13:38:53 +02:00
|
|
|
OrderedHashmap *files;
|
2012-08-14 22:02:24 +02:00
|
|
|
MMapCache *mmap;
|
2011-12-30 16:01:33 +01:00
|
|
|
|
|
|
|
Location current_location;
|
2012-07-13 00:29:26 +02:00
|
|
|
|
2011-12-30 16:01:33 +01:00
|
|
|
JournalFile *current_file;
|
|
|
|
uint64_t current_field;
|
|
|
|
|
2013-04-11 15:27:55 +02:00
|
|
|
Match *level0, *level1, *level2;
|
2012-07-11 01:08:38 +02:00
|
|
|
|
2013-06-27 01:55:48 +02:00
|
|
|
pid_t original_pid;
|
|
|
|
|
|
|
|
int inotify_fd;
|
2012-07-11 01:08:38 +02:00
|
|
|
unsigned current_invalidate_counter, last_invalidate_counter;
|
2013-06-27 01:55:48 +02:00
|
|
|
usec_t last_process_usec;
|
2012-10-18 03:29:19 +02:00
|
|
|
|
2016-01-27 18:59:29 +01:00
|
|
|
/* Iterating through unique fields and their data values */
|
2012-10-18 03:29:19 +02:00
|
|
|
char *unique_field;
|
|
|
|
JournalFile *unique_file;
|
|
|
|
uint64_t unique_offset;
|
2012-10-26 20:05:19 +02:00
|
|
|
|
2016-01-27 18:59:29 +01:00
|
|
|
/* Iterating through known fields */
|
|
|
|
JournalFile *fields_file;
|
|
|
|
uint64_t fields_offset;
|
|
|
|
uint64_t fields_hash_table_index;
|
|
|
|
char *fields_buffer;
|
|
|
|
size_t fields_buffer_allocated;
|
|
|
|
|
2013-06-27 01:55:48 +02:00
|
|
|
int flags;
|
|
|
|
|
2016-01-27 18:59:29 +01:00
|
|
|
bool on_network:1;
|
|
|
|
bool no_new_files:1;
|
2016-04-25 00:31:24 +02:00
|
|
|
bool no_inotify:1;
|
2016-01-27 18:59:29 +01:00
|
|
|
bool unique_file_lost:1; /* File we were iterating over got
|
|
|
|
removed, and there were no more
|
|
|
|
files, so sd_j_enumerate_unique
|
|
|
|
will return a value equal to 0. */
|
|
|
|
bool fields_file_lost:1;
|
2016-02-01 09:23:58 +01:00
|
|
|
bool has_runtime_files:1;
|
|
|
|
bool has_persistent_files:1;
|
2012-11-21 00:28:00 +01:00
|
|
|
|
|
|
|
size_t data_threshold;
|
2013-03-11 23:03:13 +01:00
|
|
|
|
2013-06-27 01:55:48 +02:00
|
|
|
Hashmap *directories_by_path;
|
|
|
|
Hashmap *directories_by_wd;
|
2013-04-04 20:07:48 +02:00
|
|
|
|
2015-11-02 23:37:05 +01:00
|
|
|
Hashmap *errors;
|
2011-12-30 16:01:33 +01:00
|
|
|
};
|
|
|
|
|
2012-07-13 00:29:26 +02:00
|
|
|
char *journal_make_match_string(sd_journal *j);
|
2012-07-16 22:24:02 +02:00
|
|
|
void journal_print_header(sd_journal *j);
|
2013-04-16 05:25:57 +02:00
|
|
|
|
2013-06-10 03:50:56 +02:00
|
|
|
#define JOURNAL_FOREACH_DATA_RETVAL(j, data, l, retval) \
|
|
|
|
for (sd_journal_restart_data(j); ((retval) = sd_journal_enumerate_data((j), &(data), &(l))) > 0; )
|