Merge pull request #12887 from fbuihuu/coredump-cleanup-part-1
Coredump cleanup part 1
This commit is contained in:
@@ -22,37 +22,6 @@ enum {
|
||||
IMPORTER_STATE_EOF, /* done */
|
||||
};
|
||||
|
||||
static int iovw_put(struct iovec_wrapper *iovw, void* data, size_t len) {
|
||||
if (iovw->count >= ENTRY_FIELD_COUNT_MAX)
|
||||
return -E2BIG;
|
||||
|
||||
if (!GREEDY_REALLOC(iovw->iovec, iovw->size_bytes, iovw->count + 1))
|
||||
return log_oom();
|
||||
|
||||
iovw->iovec[iovw->count++] = IOVEC_MAKE(data, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void iovw_free_contents(struct iovec_wrapper *iovw) {
|
||||
iovw->iovec = mfree(iovw->iovec);
|
||||
iovw->size_bytes = iovw->count = 0;
|
||||
}
|
||||
|
||||
static void iovw_rebase(struct iovec_wrapper *iovw, char *old, char *new) {
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < iovw->count; i++)
|
||||
iovw->iovec[i].iov_base = (char*) iovw->iovec[i].iov_base - old + new;
|
||||
}
|
||||
|
||||
size_t iovw_size(struct iovec_wrapper *iovw) {
|
||||
size_t n = 0, i;
|
||||
|
||||
for (i = 0; i < iovw->count; i++)
|
||||
n += iovw->iovec[i].iov_len;
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
void journal_importer_cleanup(JournalImporter *imp) {
|
||||
if (imp->fd >= 0 && !imp->passive_fd) {
|
||||
@@ -62,7 +31,7 @@ void journal_importer_cleanup(JournalImporter *imp) {
|
||||
|
||||
free(imp->name);
|
||||
free(imp->buf);
|
||||
iovw_free_contents(&imp->iovw);
|
||||
iovw_free_contents(&imp->iovw, false);
|
||||
}
|
||||
|
||||
static char* realloc_buffer(JournalImporter *imp, size_t size) {
|
||||
@@ -466,7 +435,7 @@ void journal_importer_drop_iovw(JournalImporter *imp) {
|
||||
|
||||
/* This function drops processed data that along with the iovw that points at it */
|
||||
|
||||
iovw_free_contents(&imp->iovw);
|
||||
iovw_free_contents(&imp->iovw, false);
|
||||
|
||||
/* possibly reset buffer position */
|
||||
remain = imp->filled - imp->offset;
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
#include <stdbool.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include "io-util.h"
|
||||
#include "sd-id128.h"
|
||||
|
||||
#include "time-util.h"
|
||||
|
||||
/* Make sure not to make this smaller than the maximum coredump size.
|
||||
@@ -24,14 +24,6 @@
|
||||
/* The maximum number of fields in an entry */
|
||||
#define ENTRY_FIELD_COUNT_MAX 1024
|
||||
|
||||
struct iovec_wrapper {
|
||||
struct iovec *iovec;
|
||||
size_t size_bytes;
|
||||
size_t count;
|
||||
};
|
||||
|
||||
size_t iovw_size(struct iovec_wrapper *iovw);
|
||||
|
||||
typedef struct JournalImporter {
|
||||
int fd;
|
||||
bool passive_fd;
|
||||
@@ -53,6 +45,9 @@ typedef struct JournalImporter {
|
||||
sd_id128_t boot_id;
|
||||
} JournalImporter;
|
||||
|
||||
#define JOURNAL_IMPORTER_INIT(_fd) { .fd = (_fd), .iovw = {} }
|
||||
#define JOURNAL_IMPORTER_MAKE(_fd) (JournalImporter) JOURNAL_IMPORTER_INIT(_fd)
|
||||
|
||||
void journal_importer_cleanup(JournalImporter *);
|
||||
int journal_importer_process_data(JournalImporter *);
|
||||
int journal_importer_push_data(JournalImporter *, const char *data, size_t size);
|
||||
|
||||
Reference in New Issue
Block a user