]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal-remote/journal-remote-write.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2012 Zbigniew Jędrzejewski-Szmek
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 #include "alloc-util.h"
22 #include "journal-remote.h"
24 static int do_rotate(JournalFile
**f
, bool compress
, bool seal
) {
25 int r
= journal_file_rotate(f
, compress
, seal
, NULL
);
28 log_error_errno(r
, "Failed to rotate %s: %m", (*f
)->path
);
30 log_error_errno(r
, "Failed to create rotated journal: %m");
36 Writer
* writer_new(RemoteServer
*server
) {
43 memset(&w
->metrics
, 0xFF, sizeof(w
->metrics
));
45 w
->mmap
= mmap_cache_new();
55 Writer
* writer_free(Writer
*w
) {
60 log_debug("Closing journal file %s.", w
->journal
->path
);
61 journal_file_close(w
->journal
);
64 if (w
->server
&& w
->hashmap_key
)
65 hashmap_remove(w
->server
->writers
, w
->hashmap_key
);
70 mmap_cache_unref(w
->mmap
);
75 Writer
* writer_unref(Writer
*w
) {
76 if (w
&& (-- w
->n_ref
<= 0))
82 Writer
* writer_ref(Writer
*w
) {
84 assert_se(++ w
->n_ref
>= 2);
89 int writer_write(Writer
*w
,
90 struct iovec_wrapper
*iovw
,
98 assert(iovw
->count
> 0);
100 if (journal_file_rotate_suggested(w
->journal
, 0)) {
101 log_info("%s: Journal header limits reached or header out-of-date, rotating",
103 r
= do_rotate(&w
->journal
, compress
, seal
);
108 r
= journal_file_append_entry(w
->journal
, ts
, iovw
->iovec
, iovw
->count
,
109 &w
->seqnum
, NULL
, NULL
);
112 w
->server
->event_count
+= 1;
116 log_debug_errno(r
, "%s: Write failed, rotating: %m", w
->journal
->path
);
117 r
= do_rotate(&w
->journal
, compress
, seal
);
121 log_debug("%s: Successfully rotated journal", w
->journal
->path
);
123 log_debug("Retrying write.");
124 r
= journal_file_append_entry(w
->journal
, ts
, iovw
->iovec
, iovw
->count
,
125 &w
->seqnum
, NULL
, NULL
);
130 w
->server
->event_count
+= 1;