]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal-remote/journal-remote-write.c
2 This file is part of systemd.
4 Copyright 2012 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"
21 #include "journal-remote.h"
23 static int do_rotate(JournalFile
**f
, bool compress
, bool seal
) {
24 int r
= journal_file_rotate(f
, compress
, seal
, NULL
);
27 log_error_errno(r
, "Failed to rotate %s: %m", (*f
)->path
);
29 log_error_errno(r
, "Failed to create rotated journal: %m");
35 Writer
* writer_new(RemoteServer
*server
) {
42 memset(&w
->metrics
, 0xFF, sizeof(w
->metrics
));
44 w
->mmap
= mmap_cache_new();
54 Writer
* writer_free(Writer
*w
) {
59 log_debug("Closing journal file %s.", w
->journal
->path
);
60 journal_file_close(w
->journal
);
63 if (w
->server
&& w
->hashmap_key
)
64 hashmap_remove(w
->server
->writers
, w
->hashmap_key
);
69 mmap_cache_unref(w
->mmap
);
74 Writer
* writer_unref(Writer
*w
) {
75 if (w
&& (-- w
->n_ref
<= 0))
81 Writer
* writer_ref(Writer
*w
) {
83 assert_se(++ w
->n_ref
>= 2);
88 int writer_write(Writer
*w
,
89 struct iovec_wrapper
*iovw
,
97 assert(iovw
->count
> 0);
99 if (journal_file_rotate_suggested(w
->journal
, 0)) {
100 log_info("%s: Journal header limits reached or header out-of-date, rotating",
102 r
= do_rotate(&w
->journal
, compress
, seal
);
107 r
= journal_file_append_entry(w
->journal
, ts
, iovw
->iovec
, iovw
->count
,
108 &w
->seqnum
, NULL
, NULL
);
111 w
->server
->event_count
+= 1;
115 log_debug_errno(r
, "%s: Write failed, rotating: %m", w
->journal
->path
);
116 r
= do_rotate(&w
->journal
, compress
, seal
);
120 log_debug("%s: Successfully rotated journal", w
->journal
->path
);
122 log_debug("Retrying write.");
123 r
= journal_file_append_entry(w
->journal
, ts
, iovw
->iovec
, iovw
->count
,
124 &w
->seqnum
, NULL
, NULL
);
129 w
->server
->event_count
+= 1;