pidref: introduce hash ops that doesn't come with destructor
This commit is contained in:
+5
-6
@@ -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);
|
||||
|
||||
+2
-1
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+3
-3
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user