static int target_new(Manager *m, TargetClass class, const char *name, const char *path, Target **ret) {
_cleanup_(target_freep) Target *t = NULL;
- int r;
assert(m);
assert(ret);
if (!t->id)
return -ENOMEM;
- r = hashmap_ensure_put(&m->targets, &target_hash_ops, t->id, t);
- if (r < 0)
- return r;
-
*ret = TAKE_PTR(t);
return 0;
}
return r;
HASHMAP_FOREACH(image, images) {
- Target *t = NULL;
+ _cleanup_(target_freep) Target *t = NULL;
bool have = false;
if (IMAGE_IS_HOST(image))
log_debug("Skipping %s because it has no default component", image->path);
continue;
}
+
+ r = hashmap_ensure_put(&m->targets, &target_hash_ops, t->id, t);
+ if (r < 0)
+ return r;
+ TAKE_PTR(t);
}
return 0;
static int manager_enumerate_components(Manager *m) {
_cleanup_strv_free_ char **components = NULL;
bool have_default;
- Target *t;
int r;
r = target_list_components(NULL, &components, &have_default);
return r;
if (have_default) {
+ _cleanup_(target_freep) Target *t = NULL;
+
r = target_new(m, TARGET_HOST, "host", "sysupdate.d", &t);
if (r < 0)
return r;
+
+ r = hashmap_ensure_put(&m->targets, &target_hash_ops, t->id, t);
+ if (r < 0)
+ return r;
+ TAKE_PTR(t);
}
STRV_FOREACH(component, components) {
_cleanup_free_ char *path = NULL;
+ _cleanup_(target_freep) Target *t = NULL;
path = strjoin("sysupdate.", *component, ".d");
if (!path)
r = target_new(m, TARGET_COMPONENT, *component, path, &t);
if (r < 0)
return r;
+
+ r = hashmap_ensure_put(&m->targets, &target_hash_ops, t->id, t);
+ if (r < 0)
+ return r;
+ TAKE_PTR(t);
}
return 0;