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