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