Skip to content

Commit 4100e0f

Browse files
committed
sysv-generator: introduce hash_ops for SysvStub
This also renames free_sysvstub() -> sysvstub_free(), to follow our usual coding style.
1 parent 765ffa1 commit 4100e0f

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/sysv-generator/sysv-generator.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ typedef struct SysvStub {
6464
bool loaded;
6565
} SysvStub;
6666

67-
static SysvStub* free_sysvstub(SysvStub *s) {
67+
static SysvStub* sysvstub_free(SysvStub *s) {
6868
if (!s)
6969
return NULL;
7070

@@ -78,11 +78,12 @@ static SysvStub* free_sysvstub(SysvStub *s) {
7878
strv_free(s->wanted_by);
7979
return mfree(s);
8080
}
81-
DEFINE_TRIVIAL_CLEANUP_FUNC(SysvStub*, free_sysvstub);
81+
DEFINE_TRIVIAL_CLEANUP_FUNC(SysvStub*, sysvstub_free);
8282

83-
static void free_sysvstub_hashmapp(Hashmap **h) {
84-
hashmap_free_with_destructor(*h, free_sysvstub);
85-
}
83+
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
84+
sysvstub_hash_ops,
85+
char, string_hash_func, string_compare_func,
86+
SysvStub, sysvstub_free);
8687

8788
static int add_alias(const char *service, const char *alias) {
8889
_cleanup_free_ char *link = NULL;
@@ -728,7 +729,7 @@ static int enumerate_sysv(const LookupPaths *lp, Hashmap *all_services) {
728729

729730
FOREACH_DIRENT(de, d, log_error_errno(errno, "Failed to enumerate directory %s, ignoring: %m", *path)) {
730731
_cleanup_free_ char *fpath = NULL, *name = NULL;
731-
_cleanup_(free_sysvstubp) SysvStub *service = NULL;
732+
_cleanup_(sysvstub_freep) SysvStub *service = NULL;
732733
struct stat st;
733734

734735
if (fstatat(dirfd(d), de->d_name, &st, 0) < 0) {
@@ -894,7 +895,7 @@ static int set_dependencies_from_rcnd(const LookupPaths *lp, Hashmap *all_servic
894895
}
895896

896897
static int run(const char *dest, const char *dest_early, const char *dest_late) {
897-
_cleanup_(free_sysvstub_hashmapp) Hashmap *all_services = NULL;
898+
_cleanup_hashmap_free_ Hashmap *all_services = NULL;
898899
_cleanup_(lookup_paths_done) LookupPaths lp = {};
899900
SysvStub *service;
900901
int r;
@@ -910,7 +911,7 @@ static int run(const char *dest, const char *dest_early, const char *dest_late)
910911
if (r < 0)
911912
return r;
912913

913-
all_services = hashmap_new(&string_hash_ops);
914+
all_services = hashmap_new(&sysvstub_hash_ops);
914915
if (!all_services)
915916
return log_oom();
916917

0 commit comments

Comments
 (0)