]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal-remote/journal-remote-write.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 #include "alloc-util.h"
4 #include "journal-remote.h"
6 static int do_rotate(JournalFile
**f
, bool compress
, bool seal
) {
7 int r
= journal_file_rotate(f
, compress
, (uint64_t) -1, seal
, NULL
);
10 log_error_errno(r
, "Failed to rotate %s: %m", (*f
)->path
);
12 log_error_errno(r
, "Failed to create rotated journal: %m");
18 Writer
* writer_new(RemoteServer
*server
) {
25 memset(&w
->metrics
, 0xFF, sizeof(w
->metrics
));
27 w
->mmap
= mmap_cache_new();
37 static Writer
* writer_free(Writer
*w
) {
42 log_debug("Closing journal file %s.", w
->journal
->path
);
43 journal_file_close(w
->journal
);
46 if (w
->server
&& w
->hashmap_key
)
47 hashmap_remove(w
->server
->writers
, w
->hashmap_key
);
52 mmap_cache_unref(w
->mmap
);
57 DEFINE_TRIVIAL_REF_UNREF_FUNC(Writer
, writer
, writer_free
);
59 int writer_write(Writer
*w
,
60 struct iovec_wrapper
*iovw
,
69 assert(iovw
->count
> 0);
71 if (journal_file_rotate_suggested(w
->journal
, 0)) {
72 log_info("%s: Journal header limits reached or header out-of-date, rotating",
74 r
= do_rotate(&w
->journal
, compress
, seal
);
79 r
= journal_file_append_entry(w
->journal
, ts
, boot_id
,
80 iovw
->iovec
, iovw
->count
,
81 &w
->seqnum
, NULL
, NULL
);
84 w
->server
->event_count
+= 1;
86 } else if (r
== -EBADMSG
)
89 log_debug_errno(r
, "%s: Write failed, rotating: %m", w
->journal
->path
);
90 r
= do_rotate(&w
->journal
, compress
, seal
);
94 log_debug("%s: Successfully rotated journal", w
->journal
->path
);
96 log_debug("Retrying write.");
97 r
= journal_file_append_entry(w
->journal
, ts
, boot_id
,
98 iovw
->iovec
, iovw
->count
,
99 &w
->seqnum
, NULL
, NULL
);
104 w
->server
->event_count
+= 1;