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