diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-12-03 13:56:26 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-12-04 07:14:25 +0100 |
commit | 1b7aa998ae358d4af66d490d35ca448378650f60 (patch) | |
tree | 3fbc6054ca0f8ad1f33233554ac6a251642a8bb9 /src/libsystemd | |
parent | journald: close runtime journals before their parent directory removed (diff) | |
download | systemd-1b7aa998ae358d4af66d490d35ca448378650f60.tar.xz systemd-1b7aa998ae358d4af66d490d35ca448378650f60.zip |
journald: also remove runtime journal directories with a different machine ID
Otherwise, even if the journal files in the directories are flushed to
the persistent storage, still they are opened by e.g. journalctl, and it
may show duplicated entries.
Also, the journal files may be flushed to the persistent storage more
than once.
Diffstat (limited to 'src/libsystemd')
-rw-r--r-- | src/libsystemd/sd-journal/journal-internal.h | 1 | ||||
-rw-r--r-- | src/libsystemd/sd-journal/sd-journal.c | 35 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/libsystemd/sd-journal/journal-internal.h b/src/libsystemd/sd-journal/journal-internal.h index 259aac847d..85d5d32f96 100644 --- a/src/libsystemd/sd-journal/journal-internal.h +++ b/src/libsystemd/sd-journal/journal-internal.h @@ -128,6 +128,7 @@ struct sd_journal { char *journal_make_match_string(sd_journal *j); void journal_print_header(sd_journal *j); +int journal_get_directories(sd_journal *j, char ***ret); #define JOURNAL_FOREACH_DATA_RETVAL(j, data, l, retval) \ for (sd_journal_restart_data(j); ((retval) = sd_journal_enumerate_data((j), &(data), &(l))) > 0; ) diff --git a/src/libsystemd/sd-journal/sd-journal.c b/src/libsystemd/sd-journal/sd-journal.c index 6b9ff0a4ed..6e33c06d63 100644 --- a/src/libsystemd/sd-journal/sd-journal.c +++ b/src/libsystemd/sd-journal/sd-journal.c @@ -1494,6 +1494,41 @@ error: return r; } +int journal_get_directories(sd_journal *j, char ***ret) { + _cleanup_strv_free_ char **paths = NULL; + JournalFile *f; + const char *p; + size_t n = SIZE_MAX; + int r; + + assert(j); + assert(ret); + + /* This returns parent directories of opened journal files. */ + + ORDERED_HASHMAP_FOREACH_KEY(f, p, j->files) { + _cleanup_free_ char *d = NULL; + + /* Ignore paths generated from fd. */ + if (path_startswith(p, "/proc/")) + continue; + + r = path_extract_directory(p, &d); + if (r < 0) + return r; + + if (path_strv_contains(paths, d)) + continue; + + r = strv_extend_with_size(&paths, &n, d); + if (r < 0) + return r; + } + + *ret = TAKE_PTR(paths); + return 0; +} + static int add_file_by_name( sd_journal *j, const char *prefix, |