summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-04-13 09:10:17 +0200
committerGitHub <noreply@github.com>2023-04-13 09:10:17 +0200
commit39857544ee3794481f165e6ecc5d5a81c65f0ee9 (patch)
tree2404d8531594f1d31f8dfa7cb29024a1d41049d8 /src/shared
parent37734dc677df0ac9ddc837d11aa3f5002a4d67a0 (diff)
parente7f5525fb0a7c8eff98b2b1b5e94e25b95fed782 (diff)
downloadsystemd-39857544ee3794481f165e6ecc5d5a81c65f0ee9.tar.gz
Merge pull request #27027 from dtardon/unit-file-list-cleanup
Use _cleanup_ for UnitFileList hash
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/install.c16
-rw-r--r--src/shared/install.h3
2 files changed, 12 insertions, 7 deletions
diff --git a/src/shared/install.c b/src/shared/install.c
index 79f9ea9b0e..964092456f 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -3611,7 +3611,7 @@ int unit_file_preset_all(
return execute_preset(file_flags, &plus, &minus, &lp, config_path, NULL, mode, changes, n_changes);
}
-static UnitFileList* unit_file_list_free_one(UnitFileList *f) {
+static UnitFileList* unit_file_list_free(UnitFileList *f) {
if (!f)
return NULL;
@@ -3619,11 +3619,15 @@ static UnitFileList* unit_file_list_free_one(UnitFileList *f) {
return mfree(f);
}
-Hashmap* unit_file_list_free(Hashmap *h) {
- return hashmap_free_with_destructor(h, unit_file_list_free_one);
-}
+DEFINE_TRIVIAL_CLEANUP_FUNC(UnitFileList*, unit_file_list_free);
-DEFINE_TRIVIAL_CLEANUP_FUNC(UnitFileList*, unit_file_list_free_one);
+DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
+ unit_file_list_hash_ops_free,
+ char,
+ string_hash_func,
+ string_compare_func,
+ UnitFileList,
+ unit_file_list_free);
int unit_file_get_list(
RuntimeScope scope,
@@ -3659,7 +3663,7 @@ int unit_file_get_list(
}
FOREACH_DIRENT(de, d, return -errno) {
- _cleanup_(unit_file_list_free_onep) UnitFileList *f = NULL;
+ _cleanup_(unit_file_list_freep) UnitFileList *f = NULL;
if (!unit_name_is_valid(de->d_name, UNIT_NAME_ANY))
continue;
diff --git a/src/shared/install.h b/src/shared/install.h
index 0f9724f999..2067969f83 100644
--- a/src/shared/install.h
+++ b/src/shared/install.h
@@ -195,7 +195,8 @@ int unit_file_get_state(RuntimeScope scope, const char *root_dir, const char *fi
int unit_file_exists(RuntimeScope scope, const LookupPaths *paths, const char *name);
int unit_file_get_list(RuntimeScope scope, const char *root_dir, Hashmap *h, char **states, char **patterns);
-Hashmap* unit_file_list_free(Hashmap *h);
+
+extern const struct hash_ops unit_file_list_hash_ops_free;
InstallChangeType install_changes_add(InstallChange **changes, size_t *n_changes, InstallChangeType type, const char *path, const char *source);
void install_changes_free(InstallChange *changes, size_t n_changes);