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