diff options
author | Franck Bui <fbui@suse.com> | 2022-03-14 14:53:38 +0100 |
---|---|---|
committer | Franck Bui <fbui@suse.com> | 2023-01-16 15:04:29 +0100 |
commit | ab92e15e2070b3fc446c497734534f3e358cf06b (patch) | |
tree | 3641c9c34d56d14deae9be084895c2ac835669d6 /src/journal | |
parent | 596c3c7f1be85ea21ac4fccc25e3899ba4bf5141 (diff) | |
download | systemd-ab92e15e2070b3fc446c497734534f3e358cf06b.tar.gz |
journald: split find_journal() up
No functional change.
Diffstat (limited to 'src/journal')
-rw-r--r-- | src/journal/journald-server.c | 72 |
1 files changed, 44 insertions, 28 deletions
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index e3ce6aaea8..d31da2d129 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -416,9 +416,44 @@ static int system_journal_open(Server *s, bool flush_requested, bool relinquish_ return r; } -static ManagedJournalFile* find_journal(Server *s, uid_t uid) { +static int find_user_journal(Server *s, uid_t uid, ManagedJournalFile **ret) { + _cleanup_(managed_journal_file_closep) ManagedJournalFile *f = NULL; _cleanup_free_ char *p = NULL; - ManagedJournalFile *f; + int r; + + assert(!uid_for_system_journal(uid)); + + f = ordered_hashmap_get(s->user_journals, UID_TO_PTR(uid)); + if (f) + goto found; + + if (asprintf(&p, "%s/user-" UID_FMT ".journal", s->system_storage.path, uid) < 0) + return log_oom(); + + /* Too many open? Then let's close one (or more) */ + while (ordered_hashmap_size(s->user_journals) >= USER_JOURNALS_MAX) { + ManagedJournalFile *first; + + assert_se(first = ordered_hashmap_steal_first(s->user_journals)); + (void) managed_journal_file_close(first); + } + + r = open_journal(s, true, p, O_RDWR|O_CREAT, s->seal, &s->system_storage.metrics, &f); + if (r < 0) + return r; + + r = ordered_hashmap_put(s->user_journals, UID_TO_PTR(uid), f); + if (r < 0) + return r; + + server_add_acls(f, uid); + +found: + *ret = TAKE_PTR(f); + return 0; +} + +static ManagedJournalFile* find_journal(Server *s, uid_t uid) { int r; assert(s); @@ -446,36 +481,17 @@ static ManagedJournalFile* find_journal(Server *s, uid_t uid) { if (!IN_SET(s->storage, STORAGE_AUTO, STORAGE_PERSISTENT)) return NULL; - if (uid_for_system_journal(uid)) - return s->system_journal; - - f = ordered_hashmap_get(s->user_journals, UID_TO_PTR(uid)); - if (f) - return f; - - if (asprintf(&p, "%s/user-" UID_FMT ".journal", s->system_storage.path, uid) < 0) { - log_oom(); - return s->system_journal; - } - - /* Too many open? Then let's close one (or more) */ - while (ordered_hashmap_size(s->user_journals) >= USER_JOURNALS_MAX) { - assert_se(f = ordered_hashmap_steal_first(s->user_journals)); - (void) managed_journal_file_close(f); - } + if (!uid_for_system_journal(uid)) { + ManagedJournalFile *f = NULL; - r = open_journal(s, true, p, O_RDWR|O_CREAT, s->seal, &s->system_storage.metrics, &f); - if (r < 0) - return s->system_journal; + r = find_user_journal(s, uid, &f); + if (r >= 0) + return ASSERT_PTR(f); - r = ordered_hashmap_put(s->user_journals, UID_TO_PTR(uid), f); - if (r < 0) { - (void) managed_journal_file_close(f); - return s->system_journal; + log_warning_errno(r, "Failed to open user journal file, falling back to system journal: %m"); } - server_add_acls(f, uid); - return f; + return s->system_journal; } static int do_rotate( |