2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2016-11-06 03:40:54 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
|
2018-05-27 11:35:07 +02:00
|
|
|
#include "sd-id128.h"
|
2019-11-28 09:14:22 +01:00
|
|
|
|
|
|
|
#include "io-util.h"
|
2016-11-06 03:40:54 +01:00
|
|
|
#include "time-util.h"
|
|
|
|
|
|
|
|
/* Make sure not to make this smaller than the maximum coredump size.
|
2018-11-12 09:56:20 +01:00
|
|
|
* See JOURNAL_SIZE_MAX in coredump.c */
|
2018-11-12 10:08:45 +01:00
|
|
|
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
2016-11-06 03:40:54 +01:00
|
|
|
#define ENTRY_SIZE_MAX (1024*1024*770u)
|
|
|
|
#define DATA_SIZE_MAX (1024*1024*768u)
|
2018-11-12 10:08:45 +01:00
|
|
|
#else
|
|
|
|
#define ENTRY_SIZE_MAX (1024*1024*13u)
|
|
|
|
#define DATA_SIZE_MAX (1024*1024*11u)
|
|
|
|
#endif
|
2016-11-06 03:40:54 +01:00
|
|
|
#define LINE_CHUNK 8*1024u
|
|
|
|
|
2018-12-05 22:45:02 +01:00
|
|
|
/* The maximum number of fields in an entry */
|
|
|
|
#define ENTRY_FIELD_COUNT_MAX 1024
|
|
|
|
|
2016-11-06 03:40:54 +01:00
|
|
|
typedef struct JournalImporter {
|
|
|
|
int fd;
|
|
|
|
bool passive_fd;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
char *buf;
|
|
|
|
size_t size; /* total size of the buffer */
|
|
|
|
size_t offset; /* offset to the beginning of live data in the buffer */
|
|
|
|
size_t scanned; /* number of bytes since the beginning of data without a newline */
|
|
|
|
size_t filled; /* total number of bytes in the buffer */
|
|
|
|
|
|
|
|
size_t field_len; /* used for binary fields: the field name length */
|
|
|
|
size_t data_size; /* and the size of the binary data chunk being processed */
|
|
|
|
|
|
|
|
struct iovec_wrapper iovw;
|
|
|
|
|
|
|
|
int state;
|
|
|
|
dual_timestamp ts;
|
2018-05-27 11:35:07 +02:00
|
|
|
sd_id128_t boot_id;
|
2016-11-06 03:40:54 +01:00
|
|
|
} JournalImporter;
|
|
|
|
|
2019-06-25 15:54:44 +02:00
|
|
|
#define JOURNAL_IMPORTER_INIT(_fd) { .fd = (_fd), .iovw = {} }
|
|
|
|
#define JOURNAL_IMPORTER_MAKE(_fd) (JournalImporter) JOURNAL_IMPORTER_INIT(_fd)
|
|
|
|
|
2016-11-06 03:40:54 +01:00
|
|
|
void journal_importer_cleanup(JournalImporter *);
|
|
|
|
int journal_importer_process_data(JournalImporter *);
|
|
|
|
int journal_importer_push_data(JournalImporter *, const char *data, size_t size);
|
|
|
|
void journal_importer_drop_iovw(JournalImporter *);
|
|
|
|
bool journal_importer_eof(const JournalImporter *);
|
|
|
|
|
|
|
|
static inline size_t journal_importer_bytes_remaining(const JournalImporter *imp) {
|
|
|
|
return imp->filled;
|
|
|
|
}
|