journal-internal.h revision 6866780115a7c0af034f287d965f4bf6b02c1e6d
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering#pragma once
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering/***
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering This file is part of systemd.
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering Copyright 2011 Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering systemd is free software; you can redistribute it and/or modify it
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering under the terms of the GNU Lesser General Public License as published by
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering (at your option) any later version.
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering systemd is distributed in the hope that it will be useful, but
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering Lesser General Public License for more details.
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering You should have received a copy of the GNU Lesser General Public License
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
4871690d9e32608bbd9b18505b5326c2079c9690Allin Cottrell***/
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering#include <sys/types.h>
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering#include <inttypes.h>
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering#include <stdbool.h>
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering#include <systemd/sd-id128.h>
13790add4bf648fed816361794d8277a75253410Lennart Poettering
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering#include "journal-def.h"
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering#include "list.h"
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering#include "hashmap.h"
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering#include "set.h"
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering#include "journal-file.h"
13790add4bf648fed816361794d8277a75253410Lennart Poettering
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poetteringtypedef struct Match Match;
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poetteringtypedef struct Location Location;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmektypedef struct Directory Directory;
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringtypedef enum MatchType {
40b71e89bae4e51768db4dc50ec64c1e9c96eec4Sebastian Thorarensen MATCH_DISCRETE,
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering MATCH_OR_TERM,
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering MATCH_AND_TERM
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering} MatchType;
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poetteringstruct Match {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering MatchType type;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering Match *parent;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering LIST_FIELDS(Match, matches);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering /* For concrete matches */
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering char *data;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering size_t size;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering le64_t le_hash;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering /* For terms */
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering LIST_HEAD(Match, matches);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering};
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringtypedef enum LocationType {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering /* The first and last entries, resp. */
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering LOCATION_HEAD,
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering LOCATION_TAIL,
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering /* We already read the entry we currently point to, and the
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering * next one to read should probably not be this one again. */
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering LOCATION_DISCRETE,
2de56f70941eaf91a4520bf33de47a87ebd8b2cbZbigniew Jędrzejewski-Szmek
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering /* We should seek to the precise location specified, and
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering * return it, as we haven't read it yet. */
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering LOCATION_SEEK
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering} LocationType;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringstruct Location {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering LocationType type;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering bool seqnum_set;
13790add4bf648fed816361794d8277a75253410Lennart Poettering bool realtime_set;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering bool monotonic_set;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering bool xor_hash_set;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering uint64_t seqnum;
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering sd_id128_t seqnum_id;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering uint64_t realtime;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering uint64_t monotonic;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering sd_id128_t boot_id;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering uint64_t xor_hash;
13790add4bf648fed816361794d8277a75253410Lennart Poettering};
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poetteringstruct Directory {
13790add4bf648fed816361794d8277a75253410Lennart Poettering char *path;
13790add4bf648fed816361794d8277a75253410Lennart Poettering int wd;
13790add4bf648fed816361794d8277a75253410Lennart Poettering bool is_root;
13790add4bf648fed816361794d8277a75253410Lennart Poettering};
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poetteringstruct sd_journal {
13790add4bf648fed816361794d8277a75253410Lennart Poettering int flags;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering char *path;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering Hashmap *files;
2de56f70941eaf91a4520bf33de47a87ebd8b2cbZbigniew Jędrzejewski-Szmek MMapCache *mmap;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering Location current_location;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering JournalFile *current_file;
13790add4bf648fed816361794d8277a75253410Lennart Poettering uint64_t current_field;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering Hashmap *directories_by_path;
13790add4bf648fed816361794d8277a75253410Lennart Poettering Hashmap *directories_by_wd;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering int inotify_fd;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering Match *level0, *level1, *level2;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering unsigned current_invalidate_counter, last_invalidate_counter;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering char *unique_field;
13790add4bf648fed816361794d8277a75253410Lennart Poettering JournalFile *unique_file;
13790add4bf648fed816361794d8277a75253410Lennart Poettering uint64_t unique_offset;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering bool on_network;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering size_t data_threshold;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering Set *errors;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering usec_t last_process_usec;
13790add4bf648fed816361794d8277a75253410Lennart Poettering};
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poetteringchar *journal_make_match_string(sd_journal *j);
13790add4bf648fed816361794d8277a75253410Lennart Poetteringvoid journal_print_header(sd_journal *j);
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poetteringstatic inline void journal_closep(sd_journal **j) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering sd_journal_close(*j);
13790add4bf648fed816361794d8277a75253410Lennart Poettering}
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering#define _cleanup_journal_close_ _cleanup_(journal_closep)
13790add4bf648fed816361794d8277a75253410Lennart Poettering