summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2014-10-15 00:23:21 +0200
committerMichal Schmidt <mschmidt@redhat.com>2014-10-23 17:38:02 +0200
commit7c0b05e58ba6a74317a332c475196c656b321829 (patch)
tree420d16f1c82d5efa4c410d2fb5c21d70c97b599a
parent7ad63f57b6ce7ae9e3cc19dcb441f0a4494fa3f2 (diff)
unit: adjust for the possibility of set_move() failing
-rw-r--r--src/core/unit.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/core/unit.c b/src/core/unit.c
index 41b9ba4a79..e40e6f2068 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -553,29 +553,38 @@ const char* unit_sub_state_to_string(Unit *u) {
return UNIT_VTABLE(u)->sub_state_to_string(u);
}
-static void complete_move(Set **s, Set **other) {
+static int complete_move(Set **s, Set **other) {
+ int r;
+
assert(s);
assert(other);
if (!*other)
- return;
+ return 0;
- if (*s)
- set_move(*s, *other);
- else {
+ if (*s) {
+ r = set_move(*s, *other);
+ if (r < 0)
+ return r;
+ } else {
*s = *other;
*other = NULL;
}
+
+ return 0;
}
-static void merge_names(Unit *u, Unit *other) {
+static int merge_names(Unit *u, Unit *other) {
char *t;
Iterator i;
+ int r;
assert(u);
assert(other);
- complete_move(&u->names, &other->names);
+ r = complete_move(&u->names, &other->names);
+ if (r < 0)
+ return r;
set_free_free(other->names);
other->names = NULL;
@@ -583,6 +592,8 @@ static void merge_names(Unit *u, Unit *other) {
SET_FOREACH(t, u->names, i)
assert_se(hashmap_replace(u->manager->units, t, u) == 0);
+
+ return 0;
}
static int reserve_dependencies(Unit *u, Unit *other, UnitDependency d) {
@@ -639,7 +650,8 @@ static void merge_dependencies(Unit *u, Unit *other, const char *other_id, UnitD
if (back)
maybe_warn_about_dependency(u->id, other_id, d);
- complete_move(&u->dependencies[d], &other->dependencies[d]);
+ /* The move cannot fail. The caller must have performed a reservation. */
+ assert_se(complete_move(&u->dependencies[d], &other->dependencies[d]) == 0);
set_free(other->dependencies[d]);
other->dependencies[d] = NULL;
@@ -694,7 +706,9 @@ int unit_merge(Unit *u, Unit *other) {
}
/* Merge names */
- merge_names(u, other);
+ r = merge_names(u, other);
+ if (r < 0)
+ return r;
/* Redirect all references */
while (other->refs)