[systemd-devel] [PATCH 06/26] install: make InstallContext::{will_install, have_installed} LinkedHashmaps
Michal Schmidt
mschmidt at redhat.com
Thu Oct 16 00:50:44 PDT 2014
It appears order may matter here. Use LinkedHashmaps to be safe.
---
src/shared/install.c | 40 ++++++++++++++++++++--------------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/src/shared/install.c b/src/shared/install.c
index ff5dcba..4b9fb7a 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -41,8 +41,8 @@
#include "special.h"
typedef struct {
- Hashmap *will_install;
- Hashmap *have_installed;
+ LinkedHashmap *will_install;
+ LinkedHashmap *have_installed;
} InstallContext;
static int in_search_path(const char *path, char **search) {
@@ -844,16 +844,16 @@ static void install_info_free(InstallInfo *i) {
free(i);
}
-static void install_info_hashmap_free(Hashmap *m) {
+static void install_info_hashmap_free(LinkedHashmap *m) {
InstallInfo *i;
if (!m)
return;
- while ((i = hashmap_steal_first(m)))
+ while ((i = linked_hashmap_steal_first(m)))
install_info_free(i);
- hashmap_free(m);
+ linked_hashmap_free(m);
}
static void install_context_done(InstallContext *c) {
@@ -881,11 +881,11 @@ static int install_info_add(
if (!unit_name_is_valid(name, TEMPLATE_VALID))
return -EINVAL;
- if (hashmap_get(c->have_installed, name) ||
- hashmap_get(c->will_install, name))
+ if (linked_hashmap_get(c->have_installed, name) ||
+ linked_hashmap_get(c->will_install, name))
return 0;
- r = hashmap_ensure_allocated(&c->will_install, &string_hash_ops);
+ r = linked_hashmap_ensure_allocated(&c->will_install, &string_hash_ops);
if (r < 0)
return r;
@@ -907,7 +907,7 @@ static int install_info_add(
}
}
- r = hashmap_put(c->will_install, i->name, i);
+ r = linked_hashmap_put(c->will_install, i->name, i);
if (r < 0)
goto fail;
@@ -1180,7 +1180,7 @@ static int unit_file_can_install(
if (r < 0)
return r;
- assert_se(i = hashmap_first(c.will_install));
+ assert_se(i = linked_hashmap_first(c.will_install));
r = unit_file_search(&c, i, paths, root_dir, allow_symlink, true);
@@ -1401,13 +1401,13 @@ static int install_context_apply(
assert(paths);
assert(config_path);
- while ((i = hashmap_first(c->will_install))) {
+ while ((i = linked_hashmap_first(c->will_install))) {
- q = hashmap_ensure_allocated(&c->have_installed, &string_hash_ops);
+ q = linked_hashmap_ensure_allocated(&c->have_installed, &string_hash_ops);
if (q < 0)
return q;
- assert_se(hashmap_move_one(c->have_installed, c->will_install, i->name) == 0);
+ assert_se(linked_hashmap_move_one(c->have_installed, c->will_install, i->name) == 0);
q = unit_file_search(c, i, paths, root_dir, false, true);
if (q < 0) {
@@ -1442,13 +1442,13 @@ static int install_context_mark_for_removal(
/* Marks all items for removal */
- while ((i = hashmap_first(c->will_install))) {
+ while ((i = linked_hashmap_first(c->will_install))) {
- q = hashmap_ensure_allocated(&c->have_installed, &string_hash_ops);
+ q = linked_hashmap_ensure_allocated(&c->have_installed, &string_hash_ops);
if (q < 0)
return q;
- assert_se(hashmap_move_one(c->have_installed, c->will_install, i->name) == 0);
+ assert_se(linked_hashmap_move_one(c->have_installed, c->will_install, i->name) == 0);
q = unit_file_search(c, i, paths, root_dir, false, true);
if (q == -ENOENT) {
@@ -1544,12 +1544,12 @@ int unit_file_add_dependency(
return r;
}
- while ((info = hashmap_first(c.will_install))) {
- r = hashmap_ensure_allocated(&c.have_installed, &string_hash_ops);
+ while ((info = linked_hashmap_first(c.will_install))) {
+ r = linked_hashmap_ensure_allocated(&c.have_installed, &string_hash_ops);
if (r < 0)
return r;
- assert_se(hashmap_move_one(c.have_installed, c.will_install, info->name) == 0);
+ assert_se(linked_hashmap_move_one(c.have_installed, c.will_install, info->name) == 0);
r = unit_file_search(&c, info, &paths, root_dir, false, false);
if (r < 0)
@@ -1720,7 +1720,7 @@ int unit_file_set_default(
if (r < 0)
return r;
- assert_se(i = hashmap_first(c.will_install));
+ assert_se(i = linked_hashmap_first(c.will_install));
r = unit_file_search(&c, i, &paths, root_dir, false, true);
if (r < 0)
--
2.1.0
More information about the systemd-devel
mailing list