From: Yu Watanabe Date: Sat, 12 Apr 2025 02:16:26 +0000 (+0900) Subject: coredump: replace custom cleanup function with specific hash_ops with destructor X-Git-Tag: v258-rc1~791^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=855800aaecb54a45c416193066cea9059a4d647c;p=thirdparty%2Fsystemd.git coredump: replace custom cleanup function with specific hash_ops with destructor --- diff --git a/src/coredump/coredump-vacuum.c b/src/coredump/coredump-vacuum.c index 8e2febd5810..3f99d04cf00 100644 --- a/src/coredump/coredump-vacuum.c +++ b/src/coredump/coredump-vacuum.c @@ -38,11 +38,10 @@ static VacuumCandidate* vacuum_candidate_free(VacuumCandidate *c) { } DEFINE_TRIVIAL_CLEANUP_FUNC(VacuumCandidate*, vacuum_candidate_free); -static Hashmap* vacuum_candidate_hashmap_free(Hashmap *h) { - return hashmap_free_with_destructor(h, vacuum_candidate_free); -} - -DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, vacuum_candidate_hashmap_free); +DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR( + vacuum_candidate_hash_ops, + void, trivial_hash_func, trivial_compare_func, + VacuumCandidate, vacuum_candidate_free); static int uid_from_file_name(const char *filename, uid_t *uid) { const char *p, *e, *u; @@ -141,7 +140,7 @@ int coredump_vacuum(int exclude_fd, uint64_t keep_free, uint64_t max_use) { } for (;;) { - _cleanup_(vacuum_candidate_hashmap_freep) Hashmap *h = NULL; + _cleanup_hashmap_free_ Hashmap *h = NULL; VacuumCandidate *worst = NULL; uint64_t sum = 0; @@ -171,10 +170,6 @@ int coredump_vacuum(int exclude_fd, uint64_t keep_free, uint64_t max_use) { if (exclude_fd >= 0 && stat_inode_same(&exclude_st, &st)) continue; - r = hashmap_ensure_allocated(&h, NULL); - if (r < 0) - return log_oom(); - t = timespec_load(&st.st_mtim); c = hashmap_get(h, UID_TO_PTR(uid)); @@ -197,7 +192,7 @@ int coredump_vacuum(int exclude_fd, uint64_t keep_free, uint64_t max_use) { return r; n->oldest_mtime = t; - r = hashmap_put(h, UID_TO_PTR(uid), n); + r = hashmap_ensure_put(&h, &vacuum_candidate_hash_ops, UID_TO_PTR(uid), n); if (r < 0) return log_oom();