Merge pull request #18299 from ssahani/ensure-put

More use of hashmap_ensure_put and ordered_hashmap_ensure_put
This commit is contained in:
Yu Watanabe
2021-01-19 08:42:26 +09:00
committed by GitHub
15 changed files with 44 additions and 108 deletions
+1 -5
View File
@@ -104,11 +104,7 @@ static int add_process(
if (r < 0)
return r;
r = hashmap_ensure_allocated(&cg->pids, &trivial_hash_ops);
if (r < 0)
return r;
return hashmap_put(cg->pids, PID_TO_PTR(pid), (void*) name);
return hashmap_ensure_put(&cg->pids, &trivial_hash_ops, PID_TO_PTR(pid), (void*) name);
}
static void remove_cgroup(Hashmap *cgroups, struct CGroupInfo *cg) {
+3 -4
View File
@@ -2391,14 +2391,13 @@ int varlink_server_bind_method(VarlinkServer *s, const char *method, VarlinkMeth
if (startswith(method, "org.varlink.service."))
return log_debug_errno(SYNTHETIC_ERRNO(EEXIST), "Cannot bind server to '%s'.", method);
if (hashmap_ensure_allocated(&s->methods, &string_hash_ops) < 0)
return log_oom_debug();
m = strdup(method);
if (!m)
return log_oom_debug();
r = hashmap_put(s->methods, m, callback);
r = hashmap_ensure_put(&s->methods, &string_hash_ops, m, callback);
if (r == -ENOMEM)
return log_oom_debug();
if (r < 0)
return log_debug_errno(r, "Failed to register callback: %m");
if (r > 0)