bus-polkit: port polkit_registry to use value destructors in hash_ops
This commit is contained in:
committed by
Luca Boccassi
parent
d04c1a1c8e
commit
2a1ffd3e3a
+10
-11
@@ -236,6 +236,14 @@ static AsyncPolkitQuery *async_polkit_query_free(AsyncPolkitQuery *q) {
|
||||
DEFINE_PRIVATE_TRIVIAL_REF_UNREF_FUNC(AsyncPolkitQuery, async_polkit_query, async_polkit_query_free);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(AsyncPolkitQuery*, async_polkit_query_unref);
|
||||
|
||||
DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
|
||||
async_polkit_query_hash_ops,
|
||||
void,
|
||||
trivial_hash_func,
|
||||
trivial_compare_func,
|
||||
AsyncPolkitQuery,
|
||||
async_polkit_query_unref);
|
||||
|
||||
static int async_polkit_defer(sd_event_source *s, void *userdata) {
|
||||
AsyncPolkitQuery *q = ASSERT_PTR(userdata);
|
||||
|
||||
@@ -557,7 +565,7 @@ int bus_verify_polkit_async_full(
|
||||
return -ENOMEM;
|
||||
|
||||
if (!q->registry) {
|
||||
r = hashmap_ensure_put(registry, /* hash_ops= */ NULL, call, q);
|
||||
r = hashmap_ensure_put(registry, &async_polkit_query_hash_ops, call, q);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -576,15 +584,6 @@ int bus_verify_polkit_async_full(
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
Hashmap *bus_verify_polkit_async_registry_free(Hashmap *registry) {
|
||||
#if ENABLE_POLKIT
|
||||
return hashmap_free_with_destructor(registry, async_polkit_query_unref);
|
||||
#else
|
||||
assert(hashmap_isempty(registry));
|
||||
return hashmap_free(registry);
|
||||
#endif
|
||||
}
|
||||
|
||||
static int varlink_check_good_user(Varlink *link, uid_t good_user) {
|
||||
int r;
|
||||
|
||||
@@ -795,7 +794,7 @@ int varlink_verify_polkit_async(
|
||||
return -ENOMEM;
|
||||
|
||||
if (!q->registry) {
|
||||
r = hashmap_ensure_put(registry, /* hash_ops= */ NULL, link, q);
|
||||
r = hashmap_ensure_put(registry, &async_polkit_query_hash_ops, link, q);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -14,8 +14,6 @@ static inline int bus_verify_polkit_async(sd_bus_message *call, const char *acti
|
||||
return bus_verify_polkit_async_full(call, action, details, false, UID_INVALID, registry, ret_error);
|
||||
}
|
||||
|
||||
Hashmap *bus_verify_polkit_async_registry_free(Hashmap *registry);
|
||||
|
||||
int varlink_verify_polkit_async(Varlink *link, sd_bus *bus, const char *action, const char **details, uid_t good_user, Hashmap **registry);
|
||||
|
||||
/* A JsonDispatch initializer that makes sure the allowInteractiveAuthentication boolean field we want for
|
||||
|
||||
Reference in New Issue
Block a user