1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 #include "alloc-util.h"
5 #include "journal-remote-parse.h"
6 #include "journald-native.h"
7 #include "parse-util.h"
8 #include "string-util.h"
10 void source_free(RemoteSource
*source
) {
14 journal_importer_cleanup(&source
->importer
);
16 log_debug("Writer ref count %u", source
->writer
->n_ref
);
17 writer_unref(source
->writer
);
19 sd_event_source_unref(source
->event
);
20 sd_event_source_unref(source
->buffer_event
);
26 * Initialize zero-filled source with given values. On success, takes
27 * ownership of fd, name, and writer, otherwise does not touch them.
29 RemoteSource
* source_new(int fd
, bool passive_fd
, char *name
, Writer
*writer
) {
32 log_debug("Creating source for %sfd:%d (%s)",
33 passive_fd
? "passive " : "", fd
, name
);
37 source
= new0(RemoteSource
, 1);
41 source
->importer
= JOURNAL_IMPORTER_MAKE(fd
);
42 source
->importer
.passive_fd
= passive_fd
;
43 source
->importer
.name
= name
;
45 source
->writer
= writer
;
50 int process_source(RemoteSource
*source
, JournalFileFlags file_flags
) {
54 assert(source
->writer
);
56 r
= journal_importer_process_data(&source
->importer
);
60 /* We have a full event */
61 log_trace("Received full event from source@%p fd:%d (%s)",
62 source
, source
->importer
.fd
, source
->importer
.name
);
64 if (source
->importer
.iovw
.count
== 0) {
65 log_warning("Entry with no payload, skipping");
69 assert(source
->importer
.iovw
.iovec
);
71 r
= writer_write(source
->writer
,
72 &source
->importer
.iovw
,
74 &source
->importer
.boot_id
,
77 log_warning_errno(r
, "Entry is invalid, ignoring.");
80 log_error_errno(r
, "Failed to write entry of %zu bytes: %m",
81 iovw_size(&source
->importer
.iovw
));
86 journal_importer_drop_iovw(&source
->importer
);