sd-journal: use hash_ops with destructor that closes JournalFile

This commit is contained in:
Yu Watanabe
2025-04-13 09:57:19 +09:00
parent c5ed193516
commit 8eb4ce4118
3 changed files with 9 additions and 2 deletions
+5
View File
@@ -92,6 +92,11 @@
# pragma GCC diagnostic ignored "-Waddress-of-packed-member"
#endif
DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
journal_file_hash_ops_by_path,
char, path_hash_func, path_compare,
JournalFile, journal_file_close);
static int mmap_prot_from_open_flags(int flags) {
switch (flags & O_ACCMODE) {
case O_RDONLY:
+2
View File
@@ -145,6 +145,8 @@ typedef struct {
uint64_t hash;
} EntryItem;
extern const struct hash_ops journal_file_hash_ops_by_path;
int journal_file_open(
int fd,
const char *fname,
+2 -2
View File
@@ -2296,7 +2296,7 @@ static sd_journal *journal_new(int flags, const char *path, const char *namespac
return NULL;
}
j->files = ordered_hashmap_new(&path_hash_ops);
j->files = ordered_hashmap_new(&journal_file_hash_ops_by_path);
if (!j->files)
return NULL;
@@ -2548,7 +2548,7 @@ _public_ void sd_journal_close(sd_journal *j) {
if (j->mmap)
mmap_cache_stats_log_debug(j->mmap);
ordered_hashmap_free_with_destructor(j->files, journal_file_close);
ordered_hashmap_free(j->files);
iterated_cache_free(j->files_cache);
hashmap_free(j->directories_by_path);