]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal-remote/journal-remote-parse.c
6a194e7f9f1ee41312057662c7fa0a830fba44b9
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2014 Zbigniew Jędrzejewski-Szmek
8 #include "alloc-util.h"
10 #include "journal-remote-parse.h"
11 #include "journald-native.h"
12 #include "parse-util.h"
13 #include "string-util.h"
15 void source_free(RemoteSource
*source
) {
19 journal_importer_cleanup(&source
->importer
);
21 log_debug("Writer ref count %i", source
->writer
->n_ref
);
22 writer_unref(source
->writer
);
24 sd_event_source_unref(source
->event
);
25 sd_event_source_unref(source
->buffer_event
);
31 * Initialize zero-filled source with given values. On success, takes
32 * ownership of fd, name, and writer, otherwise does not touch them.
34 RemoteSource
* source_new(int fd
, bool passive_fd
, char *name
, Writer
*writer
) {
38 log_debug("Creating source for %sfd:%d (%s)",
39 passive_fd
? "passive " : "", fd
, name
);
43 source
= new0(RemoteSource
, 1);
47 source
->importer
.fd
= fd
;
48 source
->importer
.passive_fd
= passive_fd
;
49 source
->importer
.name
= name
;
51 source
->writer
= writer
;
56 int process_source(RemoteSource
*source
, bool compress
, bool seal
) {
60 assert(source
->writer
);
62 r
= journal_importer_process_data(&source
->importer
);
66 /* We have a full event */
67 log_trace("Received full event from source@%p fd:%d (%s)",
68 source
, source
->importer
.fd
, source
->importer
.name
);
70 if (source
->importer
.iovw
.count
== 0) {
71 log_warning("Entry with no payload, skipping");
75 assert(source
->importer
.iovw
.iovec
);
77 r
= writer_write(source
->writer
, &source
->importer
.iovw
, &source
->importer
.ts
, compress
, seal
);
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
);