int unit_add_name(Unit *u, const char *text) {
UnitType t;
- char *s = NULL, *i = NULL;
+ char *s, *i = NULL;
int r;
assert(u);
if (i && unit_vtable[t]->no_instances)
goto fail;
- if (u->meta.type != _UNIT_TYPE_INVALID && !streq_ptr(u->meta.instance, i)) {
+ /* Ensure that this unit is either instanced or not instanced,
+ * but not both. */
+ if (u->meta.type != _UNIT_TYPE_INVALID && !u->meta.instance != !i) {
r = -EINVAL;
goto fail;
}
}
int unit_choose_id(Unit *u, const char *name) {
- char *s, *t = NULL;
+ char *s, *t = NULL, *i;
+ int r;
assert(u);
assert(name);
if (!s)
return -ENOENT;
+ if ((r = unit_name_to_instance(s, &i)) < 0)
+ return r;
+
u->meta.id = s;
+
+ free(u->meta.instance);
+ u->meta.instance = i;
+
unit_add_to_dbus_queue(u);
return 0;
if (u->meta.type != other->meta.type)
return -EINVAL;
- if (!streq_ptr(u->meta.instance, other->meta.instance))
+ if (!u->meta.instance != !other->meta.instance)
return -EINVAL;
if (other->meta.load_state != UNIT_STUB &&
void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) {
dual_timestamp ts;
+ bool unexpected;
assert(u);
assert(os < _UNIT_ACTIVE_STATE_MAX);
path_unit_notify(u, ns);
if (u->meta.job) {
- bool unexpected = false;
+ unexpected = false;
if (u->meta.job->state == JOB_WAITING)
assert_not_reached("Job type unknown");
}
- /* If this state change happened without being
- * requested by a job, then let's retroactively start
- * or stop dependencies */
-
- if (unexpected) {
- if (UNIT_IS_INACTIVE_OR_DEACTIVATING(os) && UNIT_IS_ACTIVE_OR_ACTIVATING(ns))
- retroactively_start_dependencies(u);
- else if (UNIT_IS_ACTIVE_OR_ACTIVATING(os) && UNIT_IS_INACTIVE_OR_DEACTIVATING(ns))
- retroactively_stop_dependencies(u);
- }
+ } else
+ unexpected = true;
+
+ /* If this state change happened without being requested by a
+ * job, then let's retroactively start or stop
+ * dependencies. We skip that step when deserializing, since
+ * we don't want to create any additional jobs just because
+ * something is already activated. */
+
+ if (unexpected && u->meta.manager->n_deserializing <= 0) {
+ if (UNIT_IS_INACTIVE_OR_DEACTIVATING(os) && UNIT_IS_ACTIVE_OR_ACTIVATING(ns))
+ retroactively_start_dependencies(u);
+ else if (UNIT_IS_ACTIVE_OR_ACTIVATING(os) && UNIT_IS_INACTIVE_OR_DEACTIVATING(ns))
+ retroactively_stop_dependencies(u);
}
/* Some names are special */