]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pidref: introduce hash ops that doesn't come with destructor
authorMike Yuan <me@yhndnzj.com>
Sat, 11 Nov 2023 07:48:24 +0000 (15:48 +0800)
committerMike Yuan <me@yhndnzj.com>
Sat, 11 Nov 2023 09:21:10 +0000 (17:21 +0800)
src/basic/pidref.c
src/basic/pidref.h
src/core/dbus-unit.c
src/core/unit.c

index aa4ca063babc692535e5e74dc2806979d1f4b961..69b5cad575973887a21f07b1b9b16e0200a0bb31 100644 (file)
@@ -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);
index 98ee0fef5c1062fb92fe2e5c44d2124adedb1af3..dada069357def5f23ecd97b793010a9750cc6be6 100644 (file)
@@ -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 */
index b3029ec158056e7bfe96b903924470967e26526c..038451dc7772b8d4712bcc5403077f6645bd54ec 100644 (file)
@@ -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;
         }
index 4ac8d0adc03ee0fd58509b44d9371ccbfa7b8bbf..60f461bbfdb63273e3defce37fd761395bceb029 100644 (file)
@@ -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;