From 4c8d5f0217e6c7a8cdfebafa2b0a62f865e93280 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sat, 11 Nov 2023 15:48:24 +0800 Subject: [PATCH] pidref: introduce hash ops that doesn't come with destructor --- src/basic/pidref.c | 11 +++++------ src/basic/pidref.h | 3 ++- src/core/dbus-unit.c | 2 +- src/core/unit.c | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/basic/pidref.c b/src/basic/pidref.c index aa4ca063ba..69b5cad575 100644 --- a/src/basic/pidref.c +++ b/src/basic/pidref.c @@ -278,9 +278,8 @@ static int pidref_compare_func(const PidRef *a, const PidRef *b) { return CMP(a->pid, b->pid); } -DEFINE_HASH_OPS_WITH_KEY_DESTRUCTOR( - pidref_hash_ops, - PidRef, - pidref_hash_func, - pidref_compare_func, - pidref_free); +DEFINE_HASH_OPS(pidref_hash_ops, PidRef, pidref_hash_func, pidref_compare_func); + +DEFINE_HASH_OPS_WITH_KEY_DESTRUCTOR(pidref_hash_ops_free, + PidRef, pidref_hash_func, pidref_compare_func, + pidref_free); diff --git a/src/basic/pidref.h b/src/basic/pidref.h index 98ee0fef5c..dada069357 100644 --- a/src/basic/pidref.h +++ b/src/basic/pidref.h @@ -61,4 +61,5 @@ int pidref_verify(const PidRef *pidref); #define TAKE_PIDREF(p) TAKE_GENERIC((p), PidRef, PIDREF_NULL) -extern const struct hash_ops pidref_hash_ops; /* Has destructor call for pidref_free(), i.e. expects heap allocated PidRef as keys */ +extern const struct hash_ops pidref_hash_ops; +extern const struct hash_ops pidref_hash_ops_free; /* Has destructor call for pidref_free(), i.e. expects heap allocated PidRef as keys */ diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index b3029ec158..038451dc77 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -1537,7 +1537,7 @@ int bus_unit_method_attach_processes(sd_bus_message *message, void *userdata, sd return sd_bus_error_setf(error, SD_BUS_ERROR_ACCESS_DENIED, "Process " PID_FMT " not owned by target unit's UID. Refusing.", pid); } - r = set_ensure_consume(&pids, &pidref_hash_ops, TAKE_PTR(pidref)); + r = set_ensure_consume(&pids, &pidref_hash_ops_free, TAKE_PTR(pidref)); if (r < 0) return r; } diff --git a/src/core/unit.c b/src/core/unit.c index 4ac8d0adc0..60f461bbfd 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -2865,14 +2865,14 @@ int unit_watch_pidref(Unit *u, PidRef *pid, bool exclusive) { return r; /* First, insert into the set of PIDs maintained by the unit */ - r = set_ensure_put(&u->pids, &pidref_hash_ops, pid_dup); + r = set_ensure_put(&u->pids, &pidref_hash_ops_free, pid_dup); if (r < 0) return r; pid = TAKE_PTR(pid_dup); /* continue with our copy now that we have installed it properly in our set */ /* Second, insert it into the simple global table, see if that works */ - r = hashmap_ensure_put(&u->manager->watch_pids, &pidref_hash_ops, pid, u); + r = hashmap_ensure_put(&u->manager->watch_pids, &pidref_hash_ops_free, pid, u); if (r != -EEXIST) return r; @@ -2898,7 +2898,7 @@ int unit_watch_pidref(Unit *u, PidRef *pid, bool exclusive) { new_array[n+1] = NULL; /* Make sure the hashmap is allocated */ - r = hashmap_ensure_allocated(&u->manager->watch_pids_more, &pidref_hash_ops); + r = hashmap_ensure_allocated(&u->manager->watch_pids_more, &pidref_hash_ops_free); if (r < 0) return r;