1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-22 13:33:56 +03:00

Merge pull request #18294 from ssahani/net-2

tree wide use ensure_put
This commit is contained in:
Yu Watanabe 2021-01-19 16:46:41 +09:00 committed by GitHub
commit 7b5ed18779
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 55 deletions

View File

@ -81,11 +81,7 @@ static int macsec_receive_association_new_static(MACsec *s, const char *filename
security_association_init(&c->sa); security_association_init(&c->sa);
r = ordered_hashmap_ensure_allocated(&s->receive_associations_by_section, &network_config_hash_ops); r = ordered_hashmap_ensure_put(&s->receive_associations_by_section, &network_config_hash_ops, c->section, c);
if (r < 0)
return r;
r = ordered_hashmap_put(s->receive_associations_by_section, c->section, c);
if (r < 0) if (r < 0)
return r; return r;
@ -157,11 +153,7 @@ static int macsec_receive_channel_new_static(MACsec *s, const char *filename, un
c->section = TAKE_PTR(n); c->section = TAKE_PTR(n);
r = ordered_hashmap_ensure_allocated(&s->receive_channels_by_section, &network_config_hash_ops); r = ordered_hashmap_ensure_put(&s->receive_channels_by_section, &network_config_hash_ops, c->section, c);
if (r < 0)
return r;
r = ordered_hashmap_put(s->receive_channels_by_section, c->section, c);
if (r < 0) if (r < 0)
return r; return r;
@ -216,11 +208,7 @@ static int macsec_transmit_association_new_static(MACsec *s, const char *filenam
security_association_init(&a->sa); security_association_init(&a->sa);
r = ordered_hashmap_ensure_allocated(&s->transmit_associations_by_section, &network_config_hash_ops); r = ordered_hashmap_ensure_put(&s->transmit_associations_by_section, &network_config_hash_ops, a->section, a);
if (r < 0)
return r;
r = ordered_hashmap_put(s->transmit_associations_by_section, a->section, a);
if (r < 0) if (r < 0)
return r; return r;
@ -1028,11 +1016,9 @@ static int macsec_receive_channel_verify(ReceiveChannel *c) {
"Ignoring [MACsecReceiveChannel] section from line %u", "Ignoring [MACsecReceiveChannel] section from line %u",
c->section->filename, c->section->line); c->section->filename, c->section->line);
r = ordered_hashmap_ensure_allocated(&c->macsec->receive_channels, &uint64_hash_ops); r = ordered_hashmap_ensure_put(&c->macsec->receive_channels, &uint64_hash_ops, &c->sci.as_uint64, c);
if (r < 0) if (r == -ENOMEM)
return log_oom(); return log_oom();
r = ordered_hashmap_put(c->macsec->receive_channels, &c->sci.as_uint64, c);
if (r == -EEXIST) if (r == -EEXIST)
return log_netdev_error_errno(netdev, r, return log_netdev_error_errno(netdev, r,
"%s: Multiple [MACsecReceiveChannel] sections have same SCI, " "%s: Multiple [MACsecReceiveChannel] sections have same SCI, "
@ -1120,11 +1106,9 @@ static int macsec_receive_association_verify(ReceiveAssociation *a) {
if (r < 0) if (r < 0)
return log_oom(); return log_oom();
r = ordered_hashmap_ensure_allocated(&a->macsec->receive_channels, &uint64_hash_ops); r = ordered_hashmap_ensure_put(&a->macsec->receive_channels, &uint64_hash_ops, &new_channel->sci.as_uint64, new_channel);
if (r < 0) if (r == -ENOMEM)
return log_oom(); return log_oom();
r = ordered_hashmap_put(a->macsec->receive_channels, &new_channel->sci.as_uint64, new_channel);
if (r < 0) if (r < 0)
return log_netdev_error_errno(netdev, r, return log_netdev_error_errno(netdev, r,
"%s: Failed to store receive channel at hashmap, " "%s: Failed to store receive channel at hashmap, "

View File

@ -94,11 +94,7 @@ static int address_new_static(Network *network, const char *filename, unsigned s
address->network = network; address->network = network;
address->section = TAKE_PTR(n); address->section = TAKE_PTR(n);
r = ordered_hashmap_ensure_allocated(&network->addresses_by_section, &network_config_hash_ops); r = ordered_hashmap_ensure_put(&network->addresses_by_section, &network_config_hash_ops, address->section, address);
if (r < 0)
return r;
r = ordered_hashmap_put(network->addresses_by_section, address->section, address);
if (r < 0) if (r < 0)
return r; return r;

View File

@ -499,15 +499,11 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
/* Ignore .network files that do not match the conditions. */ /* Ignore .network files that do not match the conditions. */
return 0; return 0;
r = ordered_hashmap_ensure_allocated(networks, &string_hash_ops); r = ordered_hashmap_ensure_put(networks, &string_hash_ops, network->name, network);
if (r < 0) if (r < 0)
return r; return r;
r = ordered_hashmap_put(*networks, network->name, network); TAKE_PTR(network);
if (r < 0)
return r;
network = NULL;
return 0; return 0;
} }

View File

@ -1041,10 +1041,6 @@ static int install_info_add(
return 0; return 0;
} }
r = ordered_hashmap_ensure_allocated(&c->will_process, &string_hash_ops);
if (r < 0)
return r;
i = new(UnitFileInstallInfo, 1); i = new(UnitFileInstallInfo, 1);
if (!i) if (!i)
return -ENOMEM; return -ENOMEM;
@ -1068,7 +1064,7 @@ static int install_info_add(
} }
} }
r = ordered_hashmap_put(c->will_process, i->name, i); r = ordered_hashmap_ensure_put(&c->will_process, &string_hash_ops, i->name, i);
if (r < 0) if (r < 0)
goto fail; goto fail;

View File

@ -1043,13 +1043,15 @@ static int add_user(Item *i) {
i->uid = search_uid; i->uid = search_uid;
} }
r = ordered_hashmap_ensure_allocated(&todo_uids, NULL); r = ordered_hashmap_ensure_put(&todo_uids, NULL, UID_TO_PTR(i->uid), i);
if (r < 0) if (r == -EEXIST)
return log_error_errno(r, "Requested user %s with uid " UID_FMT " and gid" GID_FMT " to be created is duplicated "
"or conflicts with another user.", i->name, i->uid, i->gid);
if (r == -ENOMEM)
return log_oom(); return log_oom();
r = ordered_hashmap_put(todo_uids, UID_TO_PTR(i->uid), i);
if (r < 0) if (r < 0)
return log_oom(); return log_error_errno(r, "Failed to store user %s with uid " UID_FMT " and gid " GID_FMT " to be created: %m",
i->name, i->uid, i->gid);
i->todo_user = true; i->todo_user = true;
log_info("Creating user %s (%s) with uid " UID_FMT " and gid " GID_FMT ".", i->name, strna(i->description), i->uid, i->gid); log_info("Creating user %s (%s) with uid " UID_FMT " and gid " GID_FMT ".", i->name, strna(i->description), i->uid, i->gid);
@ -1212,13 +1214,13 @@ static int add_group(Item *i) {
i->gid = search_uid; i->gid = search_uid;
} }
r = ordered_hashmap_ensure_allocated(&todo_gids, NULL); r = ordered_hashmap_ensure_put(&todo_gids, NULL, GID_TO_PTR(i->gid), i);
if (r < 0) if (r == -EEXIST)
return log_error_errno(r, "Requested group %s with gid "GID_FMT " to be created is duplicated or conflicts with another user.", i->name, i->gid);
if (r == -ENOMEM)
return log_oom(); return log_oom();
r = ordered_hashmap_put(todo_gids, GID_TO_PTR(i->gid), i);
if (r < 0) if (r < 0)
return log_oom(); return log_error_errno(r, "Failed to store group %s with gid " GID_FMT " to be created: %m", i->name, i->gid);
i->todo_group = true; i->todo_group = true;
log_info("Creating group %s with gid " GID_FMT ".", i->name, i->gid); log_info("Creating group %s with gid " GID_FMT ".", i->name, i->gid);

View File

@ -1977,15 +1977,16 @@ static int udev_rule_apply_token_to_event(
if (token->op == OP_ASSIGN) if (token->op == OP_ASSIGN)
ordered_hashmap_clear_free_free(event->seclabel_list); ordered_hashmap_clear_free_free(event->seclabel_list);
r = ordered_hashmap_ensure_allocated(&event->seclabel_list, NULL); r = ordered_hashmap_ensure_put(&event->seclabel_list, NULL, name, label);
if (r < 0) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r < 0)
return log_rule_error_errno(dev, rules, r, "Failed to store SECLABEL{%s}='%s': %m", name, label);;
r = ordered_hashmap_put(event->seclabel_list, name, label);
if (r < 0)
return log_oom();
log_rule_debug(dev, rules, "SECLABEL{%s}='%s'", name, label); log_rule_debug(dev, rules, "SECLABEL{%s}='%s'", name, label);
name = label = NULL;
TAKE_PTR(name);
TAKE_PTR(label);
break; break;
} }
case TK_A_ENV: { case TK_A_ENV: {