]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal-remote/journal-remote-parse.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright © 2014 Zbigniew Jędrzejewski-Szmek
6 #include "alloc-util.h"
8 #include "journal-remote-parse.h"
9 #include "journald-native.h"
10 #include "parse-util.h"
11 #include "string-util.h"
13 void source_free(RemoteSource
*source
) {
17 journal_importer_cleanup(&source
->importer
);
19 log_debug("Writer ref count %i", source
->writer
->n_ref
);
20 writer_unref(source
->writer
);
22 sd_event_source_unref(source
->event
);
23 sd_event_source_unref(source
->buffer_event
);
29 * Initialize zero-filled source with given values. On success, takes
30 * ownership of fd, name, and writer, otherwise does not touch them.
32 RemoteSource
* source_new(int fd
, bool passive_fd
, char *name
, Writer
*writer
) {
35 log_debug("Creating source for %sfd:%d (%s)",
36 passive_fd
? "passive " : "", fd
, name
);
40 source
= new0(RemoteSource
, 1);
44 source
->importer
.fd
= fd
;
45 source
->importer
.passive_fd
= passive_fd
;
46 source
->importer
.name
= name
;
48 source
->writer
= writer
;
53 int process_source(RemoteSource
*source
, bool compress
, bool seal
) {
57 assert(source
->writer
);
59 r
= journal_importer_process_data(&source
->importer
);
63 /* We have a full event */
64 log_trace("Received full event from source@%p fd:%d (%s)",
65 source
, source
->importer
.fd
, source
->importer
.name
);
67 if (source
->importer
.iovw
.count
== 0) {
68 log_warning("Entry with no payload, skipping");
72 assert(source
->importer
.iovw
.iovec
);
74 r
= writer_write(source
->writer
, &source
->importer
.iovw
, &source
->importer
.ts
, compress
, seal
);
76 log_error_errno(r
, "Entry is invalid, ignoring.");
79 log_error_errno(r
, "Failed to write entry of %zu bytes: %m",
80 iovw_size(&source
->importer
.iovw
));
85 journal_importer_drop_iovw(&source
->importer
);