goto fail;
}
- if ((r = unit_name_to_instance(s, &i)) < 0)
+ r = unit_name_to_instance(s, &i);
+ if (r < 0)
goto fail;
if (i && unit_vtable[t]->no_instances) {
goto fail;
}
- if ((r = set_put(u->names, s)) < 0) {
+ r = set_put(u->names, s);
+ if (r < 0) {
if (r == -EEXIST)
r = 0;
goto fail;
}
- if ((r = hashmap_put(u->manager->units, s, u)) < 0) {
+ r = hashmap_put(u->manager->units, s, u);
+ if (r < 0) {
set_remove(u->names, s);
goto fail;
}
u->id = s;
u->instance = i;
- LIST_PREPEND(Unit, units_by_type, u->manager->units_by_type[t], u);
+ LIST_PREPEND(units_by_type, u->manager->units_by_type[t], u);
if (UNIT_VTABLE(u)->init)
UNIT_VTABLE(u)->init(u);
if (!u->instance)
return -EINVAL;
- if (!(t = unit_name_replace_instance(name, u->instance)))
+ t = unit_name_replace_instance(name, u->instance);
+ if (!t)
return -ENOMEM;
name = t;
if (!s)
return -ENOENT;
- if ((r = unit_name_to_instance(s, &i)) < 0)
+ r = unit_name_to_instance(s, &i);
+ if (r < 0)
return r;
u->id = s;
if (u->load_state != UNIT_STUB || u->in_load_queue)
return;
- LIST_PREPEND(Unit, load_queue, u->manager->load_queue, u);
+ LIST_PREPEND(load_queue, u->manager->load_queue, u);
u->in_load_queue = true;
}
if (u->in_cleanup_queue)
return;
- LIST_PREPEND(Unit, cleanup_queue, u->manager->cleanup_queue, u);
+ LIST_PREPEND(cleanup_queue, u->manager->cleanup_queue, u);
u->in_cleanup_queue = true;
}
if (unit_check_gc(u))
return;
- LIST_PREPEND(Unit, gc_queue, u->manager->gc_queue, u);
+ LIST_PREPEND(gc_queue, u->manager->gc_queue, u);
u->in_gc_queue = true;
u->manager->n_in_gc_queue ++;
return;
}
- LIST_PREPEND(Unit, dbus_queue, u->manager->dbus_unit_queue, u);
+ LIST_PREPEND(dbus_queue, u->manager->dbus_unit_queue, u);
u->in_dbus_queue = true;
}
bidi_set_free(u, u->dependencies[d]);
if (u->type != _UNIT_TYPE_INVALID)
- LIST_REMOVE(Unit, units_by_type, u->manager->units_by_type[u->type], u);
+ LIST_REMOVE(units_by_type, u->manager->units_by_type[u->type], u);
if (u->in_load_queue)
- LIST_REMOVE(Unit, load_queue, u->manager->load_queue, u);
+ LIST_REMOVE(load_queue, u->manager->load_queue, u);
if (u->in_dbus_queue)
- LIST_REMOVE(Unit, dbus_queue, u->manager->dbus_unit_queue, u);
+ LIST_REMOVE(dbus_queue, u->manager->dbus_unit_queue, u);
if (u->in_cleanup_queue)
- LIST_REMOVE(Unit, cleanup_queue, u->manager->cleanup_queue, u);
+ LIST_REMOVE(cleanup_queue, u->manager->cleanup_queue, u);
if (u->in_gc_queue) {
- LIST_REMOVE(Unit, gc_queue, u->manager->gc_queue, u);
+ LIST_REMOVE(gc_queue, u->manager->gc_queue, u);
u->manager->n_in_gc_queue--;
}
if (u->in_cgroup_queue)
- LIST_REMOVE(Unit, cgroup_queue, u->manager->cgroup_queue, u);
+ LIST_REMOVE(cgroup_queue, u->manager->cgroup_queue, u);
if (u->cgroup_path) {
hashmap_remove(u->manager->cgroup_unit, u->cgroup_path);
SET_FOREACH(back, other->dependencies[d], i) {
UnitDependency k;
- for (k = 0; k < _UNIT_DEPENDENCY_MAX; k++)
- if ((r = set_remove_and_put(back->dependencies[k], other, u)) < 0) {
-
- if (r == -EEXIST)
- set_remove(back->dependencies[k], other);
- else
- assert(r == -ENOENT);
- }
+ for (k = 0; k < _UNIT_DEPENDENCY_MAX; k++) {
+ r = set_remove_and_put(back->dependencies[k], other, u);
+ if (r == -EEXIST)
+ set_remove(back->dependencies[k], other);
+ else
+ assert(r >= 0 || r == -ENOENT);
+ }
}
complete_move(&u->dependencies[d], &other->dependencies[d]);
if (!u->instance)
return -EINVAL;
- if (!(s = unit_name_replace_instance(name, u->instance)))
+ s = unit_name_replace_instance(name, u->instance);
+ if (!s)
return -ENOMEM;
name = s;
assert(u);
- /* Load a .service file */
+ /* Load a .{service,socket,...} file */
r = unit_load_fragment(u);
if (r < 0)
return r;
return 0;
}
+static int unit_add_mount_links(Unit *u) {
+ char **i;
+ int r;
+
+ assert(u);
+
+ STRV_FOREACH(i, u->requires_mounts_for) {
+ char prefix[strlen(*i) + 1];
+
+ PATH_FOREACH_PREFIX_MORE(prefix, *i) {
+ Unit *m;
+
+ r = manager_get_unit_by_path(u->manager, prefix, ".mount", &m);
+ if (r < 0)
+ return r;
+ if (r == 0)
+ continue;
+ if (m == u)
+ continue;
+
+ if (m->load_state != UNIT_LOADED)
+ continue;
+
+ r = unit_add_dependency(u, UNIT_AFTER, m, true);
+ if (r < 0)
+ return r;
+
+ if (m->fragment_path) {
+ r = unit_add_dependency(u, UNIT_REQUIRES, m, true);
+ if (r < 0)
+ return r;
+ }
+ }
+ }
+
+ return 0;
+}
+
int unit_load(Unit *u) {
int r;
assert(u);
if (u->in_load_queue) {
- LIST_REMOVE(Unit, load_queue, u->manager->load_queue, u);
+ LIST_REMOVE(load_queue, u->manager->load_queue, u);
u->in_load_queue = false;
}
return r;
}
-bool unit_condition_test(Unit *u) {
+static bool unit_condition_test(Unit *u) {
assert(u);
dual_timestamp_get(&u->condition_timestamp);
if (state != UNIT_ACTIVE)
return -ENOEXEC;
- if ((following = unit_following(u))) {
+ following = unit_following(u);
+ if (following) {
log_debug_unit(u->id, "Redirecting reload request from %s to %s.",
u->id, following->id);
return unit_reload(following);
if (m->n_on_console == 0)
/* unset no_console_output flag, since the console is free */
- m->no_console_output = 0;
+ m->no_console_output = false;
} else
m->n_on_console ++;
}
return r;
}
-int unit_get_related_unit(Unit *u, const char *type, Unit **_found) {
- _cleanup_free_ char *t = NULL;
- Unit *found;
-
- assert(u);
- assert(type);
- assert(_found);
-
- t = unit_name_change_suffix(u->id, type);
- if (!t)
- return -ENOMEM;
-
- assert(!unit_has_name(u, t));
-
- found = manager_get_unit(u->manager, t);
- if (!found)
- return -ENOENT;
-
- *_found = found;
- return 0;
-}
-
int unit_watch_bus_name(Unit *u, const char *name) {
assert(u);
assert(name);
unit_ref_unset(ref);
ref->unit = u;
- LIST_PREPEND(UnitRef, refs, u->refs, ref);
+ LIST_PREPEND(refs, u->refs, ref);
return u;
}
if (!ref->unit)
return;
- LIST_REMOVE(UnitRef, refs, ref->unit->refs, ref);
+ LIST_REMOVE(refs, ref->unit->refs, ref);
ref->unit = NULL;
}
-int unit_add_mount_links(Unit *u) {
- char **i;
- int r;
-
- assert(u);
-
- STRV_FOREACH(i, u->requires_mounts_for) {
- char prefix[strlen(*i) + 1];
-
- PATH_FOREACH_PREFIX_MORE(prefix, *i) {
- Unit *m;
-
- r = manager_get_unit_by_path(u->manager, prefix, ".mount", &m);
- if (r < 0)
- return r;
- if (r == 0)
- continue;
- if (m == u)
- continue;
-
- if (m->load_state != UNIT_LOADED)
- continue;
-
- r = unit_add_dependency(u, UNIT_AFTER, m, true);
- if (r < 0)
- return r;
-
- if (m->fragment_path) {
- r = unit_add_dependency(u, UNIT_REQUIRES, m, true);
- if (r < 0)
- return r;
- }
- }
- }
-
- return 0;
-}
-
int unit_exec_context_defaults(Unit *u, ExecContext *c) {
unsigned i;
int r;