]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sysv-generator: introduce hash_ops for SysvStub 37117/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 12 Apr 2025 03:16:52 +0000 (12:16 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 13 Apr 2025 01:00:57 +0000 (10:00 +0900)
This also renames free_sysvstub() -> sysvstub_free(), to follow our
usual coding style.

src/sysv-generator/sysv-generator.c

index 6520ac91e6e5d8decce908ac622ef7eb07b01a03..0878f85228a4529ff1ae7431f60221a573ffab65 100644 (file)
@@ -64,7 +64,7 @@ typedef struct SysvStub {
         bool loaded;
 } SysvStub;
 
-static SysvStub* free_sysvstub(SysvStub *s) {
+static SysvStub* sysvstub_free(SysvStub *s) {
         if (!s)
                 return NULL;
 
@@ -78,11 +78,12 @@ static SysvStub* free_sysvstub(SysvStub *s) {
         strv_free(s->wanted_by);
         return mfree(s);
 }
-DEFINE_TRIVIAL_CLEANUP_FUNC(SysvStub*, free_sysvstub);
+DEFINE_TRIVIAL_CLEANUP_FUNC(SysvStub*, sysvstub_free);
 
-static void free_sysvstub_hashmapp(Hashmap **h) {
-        hashmap_free_with_destructor(*h, free_sysvstub);
-}
+DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
+                sysvstub_hash_ops,
+                char, string_hash_func, string_compare_func,
+                SysvStub, sysvstub_free);
 
 static int add_alias(const char *service, const char *alias) {
         _cleanup_free_ char *link = NULL;
@@ -728,7 +729,7 @@ static int enumerate_sysv(const LookupPaths *lp, Hashmap *all_services) {
 
                 FOREACH_DIRENT(de, d, log_error_errno(errno, "Failed to enumerate directory %s, ignoring: %m", *path)) {
                         _cleanup_free_ char *fpath = NULL, *name = NULL;
-                        _cleanup_(free_sysvstubp) SysvStub *service = NULL;
+                        _cleanup_(sysvstub_freep) SysvStub *service = NULL;
                         struct stat st;
 
                         if (fstatat(dirfd(d), de->d_name, &st, 0) < 0) {
@@ -894,7 +895,7 @@ finish:
 }
 
 static int run(const char *dest, const char *dest_early, const char *dest_late) {
-        _cleanup_(free_sysvstub_hashmapp) Hashmap *all_services = NULL;
+        _cleanup_hashmap_free_ Hashmap *all_services = NULL;
         _cleanup_(lookup_paths_done) LookupPaths lp = {};
         SysvStub *service;
         int r;
@@ -910,7 +911,7 @@ static int run(const char *dest, const char *dest_early, const char *dest_late)
         if (r < 0)
                 return r;
 
-        all_services = hashmap_new(&string_hash_ops);
+        all_services = hashmap_new(&sysvstub_hash_ops);
         if (!all_services)
                 return log_oom();