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