diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-01-19 08:46:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-19 08:46:41 +0100 |
commit | 7b5ed18779992a62ac705952b4dc63b783be93b8 (patch) | |
tree | 9936f750fb5f6019f4abf36fdd00c612eef340cc | |
parent | Merge pull request #18300 from yuwata/analyze-verify-18252 (diff) | |
parent | udev: Use TAKE_PTR (diff) | |
download | systemd-7b5ed18779992a62ac705952b4dc63b783be93b8.tar.xz systemd-7b5ed18779992a62ac705952b4dc63b783be93b8.zip |
Merge pull request #18294 from ssahani/net-2
tree wide use ensure_put
-rw-r--r-- | src/network/netdev/macsec.c | 30 | ||||
-rw-r--r-- | src/network/networkd-address.c | 6 | ||||
-rw-r--r-- | src/network/networkd-network.c | 8 | ||||
-rw-r--r-- | src/shared/install.c | 6 | ||||
-rw-r--r-- | src/sysusers/sysusers.c | 22 | ||||
-rw-r--r-- | src/udev/udev-rules.c | 13 |
6 files changed, 30 insertions, 55 deletions
diff --git a/src/network/netdev/macsec.c b/src/network/netdev/macsec.c index 37178709cc..bef5ba1c51 100644 --- a/src/network/netdev/macsec.c +++ b/src/network/netdev/macsec.c @@ -81,11 +81,7 @@ static int macsec_receive_association_new_static(MACsec *s, const char *filename security_association_init(&c->sa); - r = ordered_hashmap_ensure_allocated(&s->receive_associations_by_section, &network_config_hash_ops); - if (r < 0) - return r; - - r = ordered_hashmap_put(s->receive_associations_by_section, c->section, c); + r = ordered_hashmap_ensure_put(&s->receive_associations_by_section, &network_config_hash_ops, c->section, c); if (r < 0) return r; @@ -157,11 +153,7 @@ static int macsec_receive_channel_new_static(MACsec *s, const char *filename, un c->section = TAKE_PTR(n); - r = ordered_hashmap_ensure_allocated(&s->receive_channels_by_section, &network_config_hash_ops); - if (r < 0) - return r; - - r = ordered_hashmap_put(s->receive_channels_by_section, c->section, c); + r = ordered_hashmap_ensure_put(&s->receive_channels_by_section, &network_config_hash_ops, c->section, c); if (r < 0) return r; @@ -216,11 +208,7 @@ static int macsec_transmit_association_new_static(MACsec *s, const char *filenam security_association_init(&a->sa); - r = ordered_hashmap_ensure_allocated(&s->transmit_associations_by_section, &network_config_hash_ops); - if (r < 0) - return r; - - r = ordered_hashmap_put(s->transmit_associations_by_section, a->section, a); + r = ordered_hashmap_ensure_put(&s->transmit_associations_by_section, &network_config_hash_ops, a->section, a); if (r < 0) return r; @@ -1028,11 +1016,9 @@ static int macsec_receive_channel_verify(ReceiveChannel *c) { "Ignoring [MACsecReceiveChannel] section from line %u", c->section->filename, c->section->line); - r = ordered_hashmap_ensure_allocated(&c->macsec->receive_channels, &uint64_hash_ops); - if (r < 0) + r = ordered_hashmap_ensure_put(&c->macsec->receive_channels, &uint64_hash_ops, &c->sci.as_uint64, c); + if (r == -ENOMEM) return log_oom(); - - r = ordered_hashmap_put(c->macsec->receive_channels, &c->sci.as_uint64, c); if (r == -EEXIST) return log_netdev_error_errno(netdev, r, "%s: Multiple [MACsecReceiveChannel] sections have same SCI, " @@ -1120,11 +1106,9 @@ static int macsec_receive_association_verify(ReceiveAssociation *a) { if (r < 0) return log_oom(); - r = ordered_hashmap_ensure_allocated(&a->macsec->receive_channels, &uint64_hash_ops); - if (r < 0) + r = ordered_hashmap_ensure_put(&a->macsec->receive_channels, &uint64_hash_ops, &new_channel->sci.as_uint64, new_channel); + if (r == -ENOMEM) return log_oom(); - - r = ordered_hashmap_put(a->macsec->receive_channels, &new_channel->sci.as_uint64, new_channel); if (r < 0) return log_netdev_error_errno(netdev, r, "%s: Failed to store receive channel at hashmap, " diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index 336dbb6486..549f5f1f82 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -94,11 +94,7 @@ static int address_new_static(Network *network, const char *filename, unsigned s address->network = network; address->section = TAKE_PTR(n); - r = ordered_hashmap_ensure_allocated(&network->addresses_by_section, &network_config_hash_ops); - if (r < 0) - return r; - - r = ordered_hashmap_put(network->addresses_by_section, address->section, address); + r = ordered_hashmap_ensure_put(&network->addresses_by_section, &network_config_hash_ops, address->section, address); if (r < 0) return r; diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 0920a9d282..97a5f1b0d1 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -499,15 +499,11 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi /* Ignore .network files that do not match the conditions. */ 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) return r; - r = ordered_hashmap_put(*networks, network->name, network); - if (r < 0) - return r; - - network = NULL; + TAKE_PTR(network); return 0; } diff --git a/src/shared/install.c b/src/shared/install.c index 302497a965..e70fa45022 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -1041,10 +1041,6 @@ static int install_info_add( return 0; } - r = ordered_hashmap_ensure_allocated(&c->will_process, &string_hash_ops); - if (r < 0) - return r; - i = new(UnitFileInstallInfo, 1); if (!i) 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) goto fail; diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index f0ec5085fc..4f78e3d065 100644 --- a/src/sysusers/sysusers.c +++ b/src/sysusers/sysusers.c @@ -1043,13 +1043,15 @@ static int add_user(Item *i) { i->uid = search_uid; } - r = ordered_hashmap_ensure_allocated(&todo_uids, NULL); - if (r < 0) + r = ordered_hashmap_ensure_put(&todo_uids, NULL, UID_TO_PTR(i->uid), i); + 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(); - - r = ordered_hashmap_put(todo_uids, UID_TO_PTR(i->uid), i); 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; 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; } - r = ordered_hashmap_ensure_allocated(&todo_gids, NULL); - if (r < 0) + r = ordered_hashmap_ensure_put(&todo_gids, NULL, GID_TO_PTR(i->gid), i); + 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(); - - r = ordered_hashmap_put(todo_gids, GID_TO_PTR(i->gid), i); 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; log_info("Creating group %s with gid " GID_FMT ".", i->name, i->gid); diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index c5c2f8cfea..db4f79fc9a 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -1977,15 +1977,16 @@ static int udev_rule_apply_token_to_event( if (token->op == OP_ASSIGN) ordered_hashmap_clear_free_free(event->seclabel_list); - r = ordered_hashmap_ensure_allocated(&event->seclabel_list, NULL); - if (r < 0) + r = ordered_hashmap_ensure_put(&event->seclabel_list, NULL, name, label); + if (r == -ENOMEM) return log_oom(); - - r = ordered_hashmap_put(event->seclabel_list, name, label); if (r < 0) - return log_oom(); + return log_rule_error_errno(dev, rules, r, "Failed to store SECLABEL{%s}='%s': %m", name, label);; + log_rule_debug(dev, rules, "SECLABEL{%s}='%s'", name, label); - name = label = NULL; + + TAKE_PTR(name); + TAKE_PTR(label); break; } case TK_A_ENV: { |