]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/journal-importer.h
Merge pull request #14592 from keszybz/simplifications
[thirdparty/systemd.git] / src / shared / journal-importer.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
b18453ed
ZJS
2
3#pragma once
4
5#include <stddef.h>
6#include <stdbool.h>
7#include <sys/uio.h>
8
c0b6ada7 9#include "sd-id128.h"
6e86b24d
ZJS
10
11#include "io-util.h"
b18453ed
ZJS
12#include "time-util.h"
13
14/* Make sure not to make this smaller than the maximum coredump size.
27f931d1 15 * See JOURNAL_SIZE_MAX in coredump.c */
25cad95c 16#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
b18453ed
ZJS
17#define ENTRY_SIZE_MAX (1024*1024*770u)
18#define DATA_SIZE_MAX (1024*1024*768u)
25cad95c
YW
19#else
20#define ENTRY_SIZE_MAX (1024*1024*13u)
21#define DATA_SIZE_MAX (1024*1024*11u)
22#endif
b18453ed
ZJS
23#define LINE_CHUNK 8*1024u
24
052c57f1
ZJS
25/* The maximum number of fields in an entry */
26#define ENTRY_FIELD_COUNT_MAX 1024
27
b18453ed
ZJS
28typedef struct JournalImporter {
29 int fd;
30 bool passive_fd;
31 char *name;
32
33 char *buf;
34 size_t size; /* total size of the buffer */
35 size_t offset; /* offset to the beginning of live data in the buffer */
36 size_t scanned; /* number of bytes since the beginning of data without a newline */
37 size_t filled; /* total number of bytes in the buffer */
38
39 size_t field_len; /* used for binary fields: the field name length */
40 size_t data_size; /* and the size of the binary data chunk being processed */
41
42 struct iovec_wrapper iovw;
43
44 int state;
45 dual_timestamp ts;
c0b6ada7 46 sd_id128_t boot_id;
b18453ed
ZJS
47} JournalImporter;
48
11e6d971
FB
49#define JOURNAL_IMPORTER_INIT(_fd) { .fd = (_fd), .iovw = {} }
50#define JOURNAL_IMPORTER_MAKE(_fd) (JournalImporter) JOURNAL_IMPORTER_INIT(_fd)
51
b18453ed
ZJS
52void journal_importer_cleanup(JournalImporter *);
53int journal_importer_process_data(JournalImporter *);
54int journal_importer_push_data(JournalImporter *, const char *data, size_t size);
55void journal_importer_drop_iovw(JournalImporter *);
56bool journal_importer_eof(const JournalImporter *);
57
58static inline size_t journal_importer_bytes_remaining(const JournalImporter *imp) {
59 return imp->filled;
60}