diff options
Diffstat (limited to 'src/journal-remote/journal-remote-write.c')
-rw-r--r-- | src/journal-remote/journal-remote-write.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/journal-remote/journal-remote-write.c b/src/journal-remote/journal-remote-write.c index f4f3b64811..2e58c6d91e 100644 --- a/src/journal-remote/journal-remote-write.c +++ b/src/journal-remote/journal-remote-write.c @@ -1,7 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include <libgen.h> + #include "alloc-util.h" #include "journal-remote.h" +#include "path-util.h" +#include "stat-util.h" static int do_rotate(ManagedJournalFile **f, MMapCache *m, JournalFileFlags file_flags) { int r; @@ -19,12 +23,13 @@ static int do_rotate(ManagedJournalFile **f, MMapCache *m, JournalFileFlags file Writer* writer_new(RemoteServer *server) { Writer *w; + int r; w = new0(Writer, 1); if (!w) return NULL; - memset(&w->metrics, 0xFF, sizeof(w->metrics)); + w->metrics = server->metrics; w->mmap = mmap_cache_new(); if (!w->mmap) @@ -33,6 +38,18 @@ Writer* writer_new(RemoteServer *server) { w->n_ref = 1; w->server = server; + if (is_dir(server->output, /* follow = */ true) > 0) { + w->output = strdup(server->output); + if (!w->output) + return NULL; + } else { + r = path_extract_directory(server->output, &w->output); + if (r < 0) { + log_error_errno(r, "Failed to find directory of file \"%s\": %m", server->output); + return NULL; + } + } + return w; } @@ -53,6 +70,8 @@ static Writer* writer_free(Writer *w) { if (w->mmap) mmap_cache_unref(w->mmap); + free(w->output); + return mfree(w); } @@ -75,6 +94,9 @@ int writer_write(Writer *w, r = do_rotate(&w->journal, w->mmap, file_flags); if (r < 0) return r; + r = journal_directory_vacuum(w->output, w->metrics.max_use, w->metrics.n_max_files, 0, NULL, /* verbose = */ true); + if (r < 0) + return r; } r = journal_file_append_entry(w->journal->file, ts, boot_id, @@ -93,6 +115,9 @@ int writer_write(Writer *w, return r; else log_debug("%s: Successfully rotated journal", w->journal->file->path); + r = journal_directory_vacuum(w->output, w->metrics.max_use, w->metrics.n_max_files, 0, NULL, /* verbose = */ true); + if (r < 0) + return r; log_debug("Retrying write."); r = journal_file_append_entry(w->journal->file, ts, boot_id, |