1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

tree-wide: use set_ensure_put()

Patch contains a coccinelle script, but it only works in some cases. Many
parts were converted by hand.

Note: I did not fix errors in return value handing. This will be done separate
to keep the patch comprehensible. No functional change is intended in this
patch.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2020-06-05 15:12:29 +02:00
parent 0f9ccd9552
commit de7fef4b6e
37 changed files with 92 additions and 330 deletions

View File

@ -0,0 +1,18 @@
@@
local idexpression r;
expression p, k, x;
@@
- r = set_ensure_allocated(&p, k);
- if (r < 0)
- return ...;
- r = set_put(p, x);
+ r = set_ensure_put(&p, k, x);
@@
local idexpression r;
expression p, k, x;
@@
- r = set_ensure_allocated(p, k);
- if (r < 0)
- return ...;
- r = set_put(*p, x);
+ r = set_ensure_put(p, k, x);

View File

@ -912,13 +912,7 @@ static int automount_deserialize_item(Unit *u, const char *key, const char *valu
if (safe_atou(value, &token) < 0)
log_unit_debug(u, "Failed to parse token value: %s", value);
else {
r = set_ensure_allocated(&a->tokens, NULL);
if (r < 0) {
log_oom();
return 0;
}
r = set_put(a->tokens, UINT_TO_PTR(token));
r = set_ensure_put(&a->tokens, NULL, UINT_TO_PTR(token));
if (r < 0)
log_unit_error_errno(u, r, "Failed to add token to set: %m");
}
@ -928,13 +922,7 @@ static int automount_deserialize_item(Unit *u, const char *key, const char *valu
if (safe_atou(value, &token) < 0)
log_unit_debug(u, "Failed to parse token value: %s", value);
else {
r = set_ensure_allocated(&a->expire_tokens, NULL);
if (r < 0) {
log_oom();
return 0;
}
r = set_put(a->expire_tokens, UINT_TO_PTR(token));
r = set_ensure_put(&a->expire_tokens, NULL, UINT_TO_PTR(token));
if (r < 0)
log_unit_error_errno(u, r, "Failed to add expire token to set: %m");
}
@ -1010,13 +998,7 @@ static int automount_dispatch_io(sd_event_source *s, int fd, uint32_t events, vo
} else
log_unit_debug(UNIT(a), "Got direct mount request on %s", a->where);
r = set_ensure_allocated(&a->tokens, NULL);
if (r < 0) {
log_unit_error(UNIT(a), "Failed to allocate token set.");
goto fail;
}
r = set_put(a->tokens, UINT_TO_PTR(packet.v5_packet.wait_queue_token));
r = set_ensure_put(&a->tokens, NULL, UINT_TO_PTR(packet.v5_packet.wait_queue_token));
if (r < 0) {
log_unit_error_errno(UNIT(a), r, "Failed to remember token: %m");
goto fail;
@ -1030,13 +1012,7 @@ static int automount_dispatch_io(sd_event_source *s, int fd, uint32_t events, vo
automount_stop_expire(a);
r = set_ensure_allocated(&a->expire_tokens, NULL);
if (r < 0) {
log_unit_error(UNIT(a), "Failed to allocate token set.");
goto fail;
}
r = set_put(a->expire_tokens, UINT_TO_PTR(packet.v5_packet.wait_queue_token));
r = set_ensure_put(&a->expire_tokens, NULL, UINT_TO_PTR(packet.v5_packet.wait_queue_token));
if (r < 0) {
log_unit_error_errno(UNIT(a), r, "Failed to remember token: %m");
goto fail;

View File

@ -606,11 +606,7 @@ static int load_bpf_progs_from_fs_to_set(Unit *u, char **filter_paths, Set **set
if (r < 0)
return log_unit_error_errno(u, r, "Loading of ingress BPF program %s failed: %m", *bpf_fs_path);
r = set_ensure_allocated(set, &filter_prog_hash_ops);
if (r < 0)
return log_unit_error_errno(u, r, "Can't allocate BPF program set: %m");
r = set_put(*set, prog);
r = set_ensure_put(set, &filter_prog_hash_ops, prog);
if (r < 0)
return log_unit_error_errno(u, r, "Can't add program to BPF program set: %m");
TAKE_PTR(prog);
@ -662,12 +658,9 @@ static int attach_custom_bpf_progs(Unit *u, const char *path, int attach_type, S
r = bpf_program_cgroup_attach(prog, attach_type, path, BPF_F_ALLOW_MULTI);
if (r < 0)
return log_unit_error_errno(u, r, "Attaching custom egress BPF program to cgroup %s failed: %m", path);
/* Remember that these BPF programs are installed now. */
r = set_ensure_allocated(set_installed, &filter_prog_hash_ops);
if (r < 0)
return log_unit_error_errno(u, r, "Can't allocate BPF program set: %m");
r = set_put(*set_installed, prog);
/* Remember that these BPF programs are installed now. */
r = set_ensure_put(set_installed, &filter_prog_hash_ops, prog);
if (r < 0)
return log_unit_error_errno(u, r, "Can't add program to BPF program set: %m");
bpf_program_ref(prog);

View File

@ -1697,10 +1697,6 @@ int bus_exec_context_set_transient_property(
else {
char **s;
r = set_ensure_allocated(&c->syscall_archs, NULL);
if (r < 0)
return r;
STRV_FOREACH(s, l) {
uint32_t a;
@ -1708,7 +1704,7 @@ int bus_exec_context_set_transient_property(
if (r < 0)
return r;
r = set_put(c->syscall_archs, UINT32_TO_PTR(a + 1));
r = set_ensure_put(&c->syscall_archs, NULL, UINT32_TO_PTR(a + 1));
if (r < 0)
return r;
}

View File

@ -3043,10 +3043,6 @@ int config_parse_syscall_archs(
return 0;
}
r = set_ensure_allocated(archs, NULL);
if (r < 0)
return log_oom();
for (;;) {
_cleanup_free_ char *word = NULL;
uint32_t a;
@ -3069,7 +3065,7 @@ int config_parse_syscall_archs(
continue;
}
r = set_put(*archs, UINT32_TO_PTR(a + 1));
r = set_ensure_put(archs, NULL, UINT32_TO_PTR(a + 1));
if (r < 0)
return log_oom();
}

View File

@ -4421,12 +4421,9 @@ int manager_update_failed_units(Manager *m, Unit *u, bool failed) {
size = set_size(m->failed_units);
if (failed) {
r = set_ensure_allocated(&m->failed_units, NULL);
r = set_ensure_put(&m->failed_units, NULL, u);
if (r < 0)
return log_oom();
if (set_put(m->failed_units, u) < 0)
return log_oom();
} else
(void) set_remove(m->failed_units, u);

View File

@ -1591,7 +1591,6 @@ static int unit_add_mount_dependencies(Unit *u) {
static int unit_add_startup_units(Unit *u) {
CGroupContext *c;
int r;
c = unit_get_cgroup_context(u);
if (!c)
@ -1602,11 +1601,7 @@ static int unit_add_startup_units(Unit *u) {
c->startup_blockio_weight == CGROUP_BLKIO_WEIGHT_INVALID)
return 0;
r = set_ensure_allocated(&u->manager->startup_units, NULL);
if (r < 0)
return r;
return set_put(u->manager->startup_units, u);
return set_ensure_put(&u->manager->startup_units, NULL, u);
}
int unit_load(Unit *u) {

View File

@ -875,12 +875,7 @@ static int parse_argv(int argc, char *argv[]) {
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Bad --facility= argument \"%s\".", fac);
r = set_ensure_allocated(&arg_facilities, NULL);
if (r < 0)
return log_oom();
r = set_put(arg_facilities, INT_TO_PTR(num));
if (r < 0)
if (set_ensure_put(&arg_facilities, NULL, INT_TO_PTR(num)) < 0)
return log_oom();
}

View File

@ -1450,10 +1450,6 @@ _public_ int sd_event_add_post(
assert_return(e->state != SD_EVENT_FINISHED, -ESTALE);
assert_return(!event_pid_changed(e), -ECHILD);
r = set_ensure_allocated(&e->post_sources, NULL);
if (r < 0)
return r;
s = source_new(e, !ret, SOURCE_POST);
if (!s)
return -ENOMEM;
@ -1462,9 +1458,10 @@ _public_ int sd_event_add_post(
s->userdata = userdata;
s->enabled = SD_EVENT_ON;
r = set_put(e->post_sources, s);
r = set_ensure_put(&e->post_sources, NULL, s);
if (r < 0)
return r;
assert(r > 0);
if (ret)
*ret = s;

View File

@ -174,15 +174,12 @@ static int set_add_message(Set **set, sd_bus_message *message) {
if (r <= 0)
return r;
r = set_ensure_allocated(set, &bus_message_hash_ops);
if (r < 0)
return r;
r = set_put(*set, message);
r = set_ensure_put(set, &bus_message_hash_ops, message);
if (r < 0)
return r;
sd_bus_message_ref(message);
return 1;
}

View File

@ -348,14 +348,7 @@ static int wireguard_resolve_handler(sd_resolve_query *q,
if (ret != 0) {
log_netdev_error(netdev, "Failed to resolve host '%s:%s': %s", peer->endpoint_host, peer->endpoint_port, gai_strerror(ret));
r = set_ensure_allocated(&w->peers_with_failed_endpoint, NULL);
if (r < 0) {
log_oom();
peer->section->invalid = true;
goto resolve_next;
}
r = set_put(w->peers_with_failed_endpoint, peer);
r = set_ensure_put(&w->peers_with_failed_endpoint, NULL, peer);
if (r < 0) {
log_netdev_error(netdev, "Failed to save a peer, dropping the peer: %m");
peer->section->invalid = true;
@ -809,15 +802,11 @@ int config_parse_wireguard_endpoint(
if (r < 0)
return log_oom();
r = set_ensure_allocated(&w->peers_with_unresolved_endpoint, NULL);
r = set_ensure_put(&w->peers_with_unresolved_endpoint, NULL, peer);
if (r < 0)
return log_oom();
r = set_put(w->peers_with_unresolved_endpoint, peer);
if (r < 0)
return r;
TAKE_PTR(peer);
return 0;
}

View File

@ -266,11 +266,7 @@ static int address_add_internal(Link *link, Set **addresses,
/* Consider address tentative until we get the real flags from the kernel */
address->flags = IFA_F_TENTATIVE;
r = set_ensure_allocated(addresses, &address_hash_ops);
if (r < 0)
return r;
r = set_put(*addresses, address);
r = set_ensure_put(addresses, &address_hash_ops, address);
if (r < 0)
return r;
if (r == 0)
@ -280,9 +276,7 @@ static int address_add_internal(Link *link, Set **addresses,
if (ret)
*ret = address;
address = NULL;
TAKE_PTR(address);
return 0;
}
@ -302,11 +296,7 @@ int address_add(Link *link, int family, const union in_addr_union *in_addr, unsi
return r;
} else if (r == 0) {
/* Take over a foreign address */
r = set_ensure_allocated(&link->addresses, &address_hash_ops);
if (r < 0)
return r;
r = set_put(link->addresses, address);
r = set_ensure_put(&link->addresses, &address_hash_ops, address);
if (r < 0)
return r;

View File

@ -664,17 +664,8 @@ int config_parse_dhcp_request_options(
continue;
}
if (ltype == AF_INET)
r = set_ensure_allocated(&network->dhcp_request_options, NULL);
else
r = set_ensure_allocated(&network->dhcp6_request_options, NULL);
if (r < 0)
return log_oom();
if (ltype == AF_INET)
r = set_put(network->dhcp_request_options, UINT32_TO_PTR(i));
else
r = set_put(network->dhcp6_request_options, UINT32_TO_PTR(i));
r = set_ensure_put(ltype == AF_INET ? &network->dhcp_request_options : &network->dhcp6_request_options,
NULL, UINT32_TO_PTR(i));
if (r < 0)
log_syntax(unit, LOG_ERR, filename, line, r,
"Failed to store DHCP request option '%s', ignoring assignment: %m", n);

View File

@ -1564,7 +1564,6 @@ int config_parse_dhcp_black_listed_ip_address(
void *userdata) {
Network *network = data;
const char *p;
int r;
assert(filename);
@ -1577,7 +1576,7 @@ int config_parse_dhcp_black_listed_ip_address(
return 0;
}
for (p = rvalue;;) {
for (const char *p = rvalue;;) {
_cleanup_free_ char *n = NULL;
union in_addr_union ip;
@ -1598,11 +1597,7 @@ int config_parse_dhcp_black_listed_ip_address(
continue;
}
r = set_ensure_allocated(&network->dhcp_black_listed_ip, NULL);
if (r < 0)
return log_oom();
r = set_put(network->dhcp_black_listed_ip, UINT32_TO_PTR(ip.in.s_addr));
r = set_ensure_put(&network->dhcp_black_listed_ip, NULL, UINT32_TO_PTR(ip.in.s_addr));
if (r < 0)
log_syntax(unit, LOG_ERR, filename, line, r,
"Failed to store DHCP black listed ip address '%s', ignoring assignment: %m", n);

View File

@ -2125,11 +2125,7 @@ static int link_append_to_master(Link *link, NetDev *netdev) {
if (r < 0)
return r;
r = set_ensure_allocated(&master->slaves, NULL);
if (r < 0)
return r;
r = set_put(master->slaves, link);
r = set_ensure_put(&master->slaves, NULL, link);
if (r <= 0)
return r;
@ -4440,16 +4436,10 @@ void link_dirty(Link *link) {
/* mark manager dirty as link is dirty */
manager_dirty(link->manager);
r = set_ensure_allocated(&link->manager->dirty_links, NULL);
if (r < 0)
/* allocation errors are ignored */
return;
r = set_put(link->manager->dirty_links, link);
r = set_ensure_put(&link->manager->dirty_links, NULL, link);
if (r <= 0)
/* don't take another ref if the link was already dirty */
/* Ignore allocation errors and don't take another ref if the link was already dirty */
return;
link_ref(link);
}

View File

@ -2309,19 +2309,11 @@ int manager_request_product_uuid(Manager *m, Link *link) {
assert_se(duid = link_get_duid(link));
r = set_ensure_allocated(&m->links_requesting_uuid, NULL);
r = set_ensure_put(&m->links_requesting_uuid, NULL, link);
if (r < 0)
return log_oom();
r = set_ensure_allocated(&m->duids_requesting_uuid, NULL);
if (r < 0)
return log_oom();
r = set_put(m->links_requesting_uuid, link);
if (r < 0)
return log_oom();
r = set_put(m->duids_requesting_uuid, duid);
r = set_ensure_put(&m->duids_requesting_uuid, NULL, duid);
if (r < 0)
return log_oom();

View File

@ -591,10 +591,6 @@ static int ndisc_router_process_rdnss(Link *link, sd_ndisc_router *rt) {
continue;
}
r = set_ensure_allocated(&link->ndisc_rdnss, &ndisc_rdnss_hash_ops);
if (r < 0)
return log_oom();
x = new(NDiscRDNSS, 1);
if (!x)
return log_oom();
@ -604,10 +600,9 @@ static int ndisc_router_process_rdnss(Link *link, sd_ndisc_router *rt) {
.valid_until = time_now + lifetime * USEC_PER_SEC,
};
r = set_put(link->ndisc_rdnss, x);
r = set_ensure_put(&link->ndisc_rdnss, &ndisc_rdnss_hash_ops, x);
if (r < 0)
return log_oom();
TAKE_PTR(x);
assert(r > 0);
@ -686,22 +681,16 @@ static void ndisc_router_process_dnssl(Link *link, sd_ndisc_router *rt) {
continue;
}
r = set_ensure_allocated(&link->ndisc_dnssl, &ndisc_dnssl_hash_ops);
if (r < 0) {
log_oom();
return;
}
s->valid_until = time_now + lifetime * USEC_PER_SEC;
r = set_put(link->ndisc_dnssl, s);
r = set_ensure_put(&link->ndisc_dnssl, &ndisc_dnssl_hash_ops, s);
if (r < 0) {
log_oom();
return;
}
s = NULL;
TAKE_PTR(s);
assert(r > 0);
link_dirty(link);
}
}
@ -979,21 +968,16 @@ int config_parse_ndisc_black_listed_prefix(
if (set_contains(network->ndisc_black_listed_prefix, &ip.in6))
continue;
r = set_ensure_allocated(&network->ndisc_black_listed_prefix, &in6_addr_hash_ops);
if (r < 0)
return log_oom();
a = newdup(struct in6_addr, &ip.in6, 1);
if (!a)
return log_oom();
r = set_put(network->ndisc_black_listed_prefix, a);
r = set_ensure_put(&network->ndisc_black_listed_prefix, &in6_addr_hash_ops, a);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r,
"Failed to store NDISC black listed prefix '%s', ignoring assignment: %m", n);
continue;
}
TAKE_PTR(a);
}

View File

@ -300,11 +300,7 @@ static int neighbor_add_internal(Link *link, Set **neighbors, int family, const
.lladdr_size = lladdr_size,
};
r = set_ensure_allocated(neighbors, &neighbor_hash_ops);
if (r < 0)
return r;
r = set_put(*neighbors, neighbor);
r = set_ensure_put(neighbors, &neighbor_hash_ops, neighbor);
if (r < 0)
return r;
if (r == 0)
@ -314,8 +310,7 @@ static int neighbor_add_internal(Link *link, Set **neighbors, int family, const
if (ret)
*ret = neighbor;
neighbor = NULL;
TAKE_PTR(neighbor);
return 0;
}
@ -332,11 +327,7 @@ int neighbor_add(Link *link, int family, const union in_addr_union *addr, const
return r;
} else if (r == 0) {
/* Neighbor is foreign, claim it as recognized */
r = set_ensure_allocated(&link->neighbors, &neighbor_hash_ops);
if (r < 0)
return r;
r = set_put(link->neighbors, neighbor);
r = set_ensure_put(&link->neighbors, &neighbor_hash_ops, neighbor);
if (r < 0)
return r;

View File

@ -1268,15 +1268,11 @@ int config_parse_dnssec_negative_trust_anchors(
continue;
}
r = set_ensure_allocated(&n->dnssec_negative_trust_anchors, &dns_name_hash_ops);
if (r < 0)
return log_oom();
r = set_put(n->dnssec_negative_trust_anchors, w);
r = set_ensure_put(&n->dnssec_negative_trust_anchors, &dns_name_hash_ops, w);
if (r < 0)
return log_oom();
if (r > 0)
w = NULL;
TAKE_PTR(w);
}
return 0;

View File

@ -209,11 +209,7 @@ static int nexthop_add_internal(Link *link, Set **nexthops, NextHop *in, NextHop
nexthop->family = in->family;
nexthop->gw = in->gw;
r = set_ensure_allocated(nexthops, &nexthop_hash_ops);
if (r < 0)
return r;
r = set_put(*nexthops, nexthop);
r = set_ensure_put(nexthops, &nexthop_hash_ops, nexthop);
if (r < 0)
return r;
if (r == 0)
@ -245,11 +241,7 @@ int nexthop_add(Link *link, NextHop *in, NextHop **ret) {
return r;
} else if (r == 0) {
/* Take over a foreign nexthop */
r = set_ensure_allocated(&link->nexthops, &nexthop_hash_ops);
if (r < 0)
return r;
r = set_put(link->nexthops, nexthop);
r = set_ensure_put(&link->nexthops, &nexthop_hash_ops, nexthop);
if (r < 0)
return r;

View File

@ -331,11 +331,7 @@ static int route_add_internal(Link *link, Set **routes, Route *in, Route **ret)
route->initrwnd = in->initrwnd;
route->lifetime = in->lifetime;
r = set_ensure_allocated(routes, &route_hash_ops);
if (r < 0)
return r;
r = set_put(*routes, route);
r = set_ensure_put(routes, &route_hash_ops, route);
if (r < 0)
return r;
if (r == 0)
@ -368,11 +364,7 @@ int route_add(Link *link, Route *in, Route **ret) {
return r;
} else if (r == 0) {
/* Take over a foreign route */
r = set_ensure_allocated(&link->routes, &route_hash_ops);
if (r < 0)
return r;
r = set_put(link->routes, route);
r = set_ensure_put(&link->routes, &route_hash_ops, route);
if (r < 0)
return r;

View File

@ -263,11 +263,7 @@ int routing_policy_rule_make_local(Manager *m, RoutingPolicyRule *rule) {
if (set_contains(m->rules_foreign, rule)) {
set_remove(m->rules_foreign, rule);
r = set_ensure_allocated(&m->rules, &routing_policy_rule_hash_ops);
if (r < 0)
return r;
r = set_put(m->rules, rule);
r = set_ensure_put(&m->rules, &routing_policy_rule_hash_ops, rule);
if (r < 0)
return r;
if (r == 0)
@ -295,11 +291,7 @@ static int routing_policy_rule_add_internal(Manager *m, Set **rules, RoutingPoli
if (r < 0)
return r;
r = set_ensure_allocated(rules, &routing_policy_rule_hash_ops);
if (r < 0)
return r;
r = set_put(*rules, rule);
r = set_ensure_put(rules, &routing_policy_rule_hash_ops, rule);
if (r < 0)
return r;
if (r == 0)
@ -1328,10 +1320,6 @@ int routing_policy_load_rules(const char *state_file, Set **rules) {
if (!l)
return -ENOMEM;
r = set_ensure_allocated(rules, &routing_policy_rule_hash_ops);
if (r < 0)
return r;
STRV_FOREACH(i, l) {
_cleanup_(routing_policy_rule_freep) RoutingPolicyRule *rule = NULL;
@ -1461,7 +1449,7 @@ int routing_policy_load_rules(const char *state_file, Set **rules) {
}
}
r = set_put(*rules, rule);
r = set_ensure_put(rules, &routing_policy_rule_hash_ops, rule);
if (r < 0) {
log_warning_errno(r, "Failed to add RPDB rule to saved DB, ignoring: %s", p);
continue;

View File

@ -1193,11 +1193,7 @@ int portable_detach(
if (path_is_absolute(marker) &&
!image_in_search_path(IMAGE_PORTABLE, marker)) {
r = set_ensure_allocated(&markers, &path_hash_ops);
if (r < 0)
return r;
r = set_put(markers, marker);
r = set_ensure_put(&markers, &path_hash_ops, marker);
if (r >= 0)
marker = NULL;
else if (r != -EEXIST)

View File

@ -108,23 +108,15 @@ static int dns_query_candidate_add_transaction(DnsQueryCandidate *c, DnsResource
} else if (set_contains(c->transactions, t))
return 0;
r = set_ensure_allocated(&c->transactions, NULL);
if (r < 0)
return r;
r = set_ensure_allocated(&t->notify_query_candidates, NULL);
if (r < 0)
return r;
r = set_ensure_allocated(&t->notify_query_candidates_done, NULL);
if (r < 0)
return r;
r = set_put(t->notify_query_candidates, c);
r = set_ensure_put(&t->notify_query_candidates, NULL, c);
if (r < 0)
return r;
r = set_put(c->transactions, t);
r = set_ensure_put(&c->transactions, NULL, t);
if (r < 0) {
(void) set_remove(t->notify_query_candidates, c);
return r;

View File

@ -1253,11 +1253,7 @@ int dns_scope_announce(DnsScope *scope, bool goodbye) {
if (!scope->announced &&
dns_resource_key_is_dnssd_ptr(z->rr->key)) {
if (!set_contains(types, dns_resource_key_name(z->rr->key))) {
r = set_ensure_allocated(&types, &dns_name_hash_ops);
if (r < 0)
return log_debug_errno(r, "Failed to allocate set: %m");
r = set_put(types, dns_resource_key_name(z->rr->key));
r = set_ensure_put(&types, &dns_name_hash_ops, dns_resource_key_name(z->rr->key));
if (r < 0)
return log_debug_errno(r, "Failed to add item to set: %m");
}

View File

@ -348,16 +348,11 @@ static void dns_stub_process_query(Manager *m, DnsStream *s, DnsPacket *p) {
/* Remember which queries belong to this stream, so that we can cancel them when the stream
* is disconnected early */
r = set_ensure_allocated(&s->queries, &trivial_hash_ops);
r = set_ensure_put(&s->queries, &trivial_hash_ops, q);
if (r < 0) {
log_oom();
goto fail;
}
if (set_put(s->queries, q) < 0) {
log_oom();
goto fail;
}
}
r = dns_query_go(q);

View File

@ -1501,11 +1501,7 @@ static int dns_transaction_make_packet_mdns(DnsTransaction *t) {
add_known_answers = true;
if (t->key->type == DNS_TYPE_ANY) {
r = set_ensure_allocated(&keys, &dns_resource_key_hash_ops);
if (r < 0)
return r;
r = set_put(keys, t->key);
r = set_ensure_put(&keys, &dns_resource_key_hash_ops, t->key);
if (r < 0)
return r;
}
@ -1571,11 +1567,7 @@ static int dns_transaction_make_packet_mdns(DnsTransaction *t) {
add_known_answers = true;
if (other->key->type == DNS_TYPE_ANY) {
r = set_ensure_allocated(&keys, &dns_resource_key_hash_ops);
if (r < 0)
return r;
r = set_put(keys, other->key);
r = set_ensure_put(&keys, &dns_resource_key_hash_ops, other->key);
if (r < 0)
return r;
}
@ -1833,23 +1825,15 @@ static int dns_transaction_add_dnssec_transaction(DnsTransaction *t, DnsResource
}
}
r = set_ensure_allocated(&t->dnssec_transactions, NULL);
if (r < 0)
return r;;
r = set_ensure_allocated(&aux->notify_transactions, NULL);
if (r < 0)
return r;
r = set_ensure_allocated(&aux->notify_transactions_done, NULL);
if (r < 0)
return r;
r = set_put(t->dnssec_transactions, aux);
r = set_ensure_put(&t->dnssec_transactions, NULL, aux);
if (r < 0)
return r;
return r;;
r = set_put(aux->notify_transactions, t);
r = set_ensure_put(&aux->notify_transactions, NULL, t);
if (r < 0) {
(void) set_remove(t->dnssec_transactions, aux);
return r;

View File

@ -393,11 +393,7 @@ static int dns_trust_anchor_load_negative(DnsTrustAnchor *d, const char *path, u
return -EINVAL;
}
r = set_ensure_allocated(&d->negative_by_name, &dns_name_hash_ops);
if (r < 0)
return log_oom();
r = set_put(d->negative_by_name, domain);
r = set_ensure_put(&d->negative_by_name, &dns_name_hash_ops, domain);
if (r < 0)
return log_oom();
if (r > 0)
@ -592,11 +588,7 @@ static int dns_trust_anchor_revoked_put(DnsTrustAnchor *d, DnsResourceRecord *rr
assert(d);
r = set_ensure_allocated(&d->revoked_by_rr, &dns_resource_record_hash_ops);
if (r < 0)
return r;
r = set_put(d->revoked_by_rr, rr);
r = set_ensure_put(&d->revoked_by_rr, &dns_resource_record_hash_ops, rr);
if (r < 0)
return r;
if (r > 0)

View File

@ -183,15 +183,11 @@ static int dns_zone_item_probe_start(DnsZoneItem *i) {
return r;
}
r = set_ensure_allocated(&t->notify_zone_items, NULL);
if (r < 0)
return r;
r = set_ensure_allocated(&t->notify_zone_items_done, NULL);
if (r < 0)
return r;
r = set_put(t->notify_zone_items, i);
r = set_ensure_put(&t->notify_zone_items, NULL, i);
if (r < 0)
return r;

View File

@ -120,11 +120,7 @@ static int parse_line(EtcHosts *hosts, unsigned nr, const char *line) {
/* Optimize the case where we don't need to store any addresses, by storing
* only the name in a dedicated Set instead of the hashmap */
r = set_ensure_allocated(&hosts->no_address, &dns_name_hash_ops);
if (r < 0)
return log_oom();
r = set_put(hosts->no_address, name);
r = set_ensure_put(&hosts->no_address, &dns_name_hash_ops, name);
if (r < 0)
return r;

View File

@ -613,11 +613,7 @@ int bus_message_print_all_properties(
return r;
if (found_properties) {
r = set_ensure_allocated(found_properties, &string_hash_ops);
if (r < 0)
return log_oom();
r = set_put(*found_properties, name);
r = set_ensure_put(found_properties, &string_hash_ops, name);
if (r < 0 && r != -EEXIST)
return log_oom();
}

View File

@ -1742,17 +1742,13 @@ int seccomp_restrict_archs(Set *archs) {
return 0;
}
int parse_syscall_archs(char **l, Set **archs) {
_cleanup_set_free_ Set *_archs = NULL;
int parse_syscall_archs(char **l, Set **ret_archs) {
_cleanup_set_free_ Set *archs = NULL;
char **s;
int r;
assert(l);
assert(archs);
r = set_ensure_allocated(&_archs, NULL);
if (r < 0)
return r;
assert(ret_archs);
STRV_FOREACH(s, l) {
uint32_t a;
@ -1761,13 +1757,12 @@ int parse_syscall_archs(char **l, Set **archs) {
if (r < 0)
return -EINVAL;
r = set_put(_archs, UINT32_TO_PTR(a + 1));
r = set_ensure_put(&archs, NULL, UINT32_TO_PTR(a + 1));
if (r < 0)
return -ENOMEM;
}
*archs = TAKE_PTR(_archs);
*ret_archs = TAKE_PTR(archs);
return 0;
}

View File

@ -105,6 +105,6 @@ extern const uint32_t seccomp_local_archs[];
DEFINE_TRIVIAL_CLEANUP_FUNC(scmp_filter_ctx, seccomp_release);
int parse_syscall_archs(char **l, Set **archs);
int parse_syscall_archs(char **l, Set **ret_archs);
uint32_t scmp_act_kill_process(void);

View File

@ -359,11 +359,7 @@ static int userdb_connect(
if (r < 0)
return log_debug_errno(r, "Failed to invoke varlink method: %m");
r = set_ensure_allocated(&iterator->links, &link_hash_ops);
if (r < 0)
return log_debug_errno(r, "Failed to allocate set: %m");
r = set_put(iterator->links, vl);
r = set_ensure_put(&iterator->links, &link_hash_ops, vl);
if (r < 0)
return log_debug_errno(r, "Failed to add varlink connection to set: %m");

View File

@ -480,12 +480,6 @@ static int add_connection_socket(Context *context, int fd) {
log_warning_errno(r, "Unable to disable idle timer, continuing: %m");
}
r = set_ensure_allocated(&context->connections, NULL);
if (r < 0) {
log_oom();
return 0;
}
c = new0(Connection, 1);
if (!c) {
log_oom();
@ -498,7 +492,7 @@ static int add_connection_socket(Context *context, int fd) {
c->server_to_client_buffer[0] = c->server_to_client_buffer[1] = -1;
c->client_to_server_buffer[0] = c->client_to_server_buffer[1] = -1;
r = set_put(context->connections, c);
r = set_ensure_put(&context->connections, NULL, c);
if (r < 0) {
free(c);
log_oom();
@ -550,12 +544,6 @@ static int add_listen_socket(Context *context, int fd) {
assert(context);
assert(fd >= 0);
r = set_ensure_allocated(&context->listen, NULL);
if (r < 0) {
log_oom();
return r;
}
r = sd_is_socket(fd, 0, SOCK_STREAM, 1);
if (r < 0)
return log_error_errno(r, "Failed to determine socket type: %m");
@ -571,7 +559,7 @@ static int add_listen_socket(Context *context, int fd) {
if (r < 0)
return log_error_errno(r, "Failed to add event source: %m");
r = set_put(context->listen, source);
r = set_ensure_put(&context->listen, NULL, source);
if (r < 0) {
log_error_errno(r, "Failed to add source to set: %m");
sd_event_source_unref(source);

View File

@ -885,13 +885,7 @@ static int set_dependencies_from_rcnd(const LookupPaths *lp, Hashmap *all_servic
service->sysv_start_priority = MAX(a*10 + b, service->sysv_start_priority);
r = set_ensure_allocated(&runlevel_services[i], NULL);
if (r < 0) {
log_oom();
goto finish;
}
r = set_put(runlevel_services[i], service);
r = set_ensure_put(&runlevel_services[i], NULL, service);
if (r < 0) {
log_oom();
goto finish;

View File

@ -3196,11 +3196,7 @@ static int link_parent(ItemArray *a) {
if (!j)
j = ordered_hashmap_get(globs, prefix);
if (j) {
r = set_ensure_allocated(&j->children, NULL);
if (r < 0)
return log_oom();
r = set_put(j->children, a);
r = set_ensure_put(&j->children, NULL, a);
if (r < 0)
return log_oom();