]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal-remote/journal-remote-parse.c
2 This file is part of systemd.
4 Copyright 2014 Zbigniew Jędrzejewski-Szmek
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 #include "alloc-util.h"
22 #include "journal-remote-parse.h"
23 #include "journald-native.h"
24 #include "parse-util.h"
25 #include "string-util.h"
27 void source_free(RemoteSource
*source
) {
31 journal_importer_cleanup(&source
->importer
);
33 log_debug("Writer ref count %i", source
->writer
->n_ref
);
34 writer_unref(source
->writer
);
36 sd_event_source_unref(source
->event
);
37 sd_event_source_unref(source
->buffer_event
);
43 * Initialize zero-filled source with given values. On success, takes
44 * ownership of fd, name, and writer, otherwise does not touch them.
46 RemoteSource
* source_new(int fd
, bool passive_fd
, char *name
, Writer
*writer
) {
50 log_debug("Creating source for %sfd:%d (%s)",
51 passive_fd
? "passive " : "", fd
, name
);
55 source
= new0(RemoteSource
, 1);
59 source
->importer
.fd
= fd
;
60 source
->importer
.passive_fd
= passive_fd
;
61 source
->importer
.name
= name
;
63 source
->writer
= writer
;
68 int process_source(RemoteSource
*source
, bool compress
, bool seal
) {
72 assert(source
->writer
);
74 r
= journal_importer_process_data(&source
->importer
);
78 /* We have a full event */
79 log_trace("Received full event from source@%p fd:%d (%s)",
80 source
, source
->importer
.fd
, source
->importer
.name
);
82 if (source
->importer
.iovw
.count
== 0) {
83 log_warning("Entry with no payload, skipping");
87 assert(source
->importer
.iovw
.iovec
);
89 r
= writer_write(source
->writer
, &source
->importer
.iovw
, &source
->importer
.ts
, compress
, seal
);
91 log_error_errno(r
, "Failed to write entry of %zu bytes: %m",
92 iovw_size(&source
->importer
.iovw
));
97 journal_importer_drop_iovw(&source
->importer
);