transaction_delete_job(tr, j, true);
assert(hashmap_isempty(tr->jobs));
-
- assert(!tr->anchor);
}
-static void transaction_find_jobs_that_matter_to_anchor(Transaction *tr, Job *j, unsigned generation) {
+static void transaction_find_jobs_that_matter_to_anchor(Job *j, unsigned generation) {
JobDependency *l;
- assert(tr);
-
/* A recursive sweep through the graph that marks all units
* that matter to the anchor job, i.e. are directly or
* indirectly a dependency of the anchor job via paths that
* are fully marked as mattering. */
- if (j)
- l = j->subject_list;
- else
- l = tr->anchor;
+ j->matters_to_anchor = true;
+ j->generation = generation;
- LIST_FOREACH(subject, l, l) {
+ LIST_FOREACH(subject, l, j->subject_list) {
/* This link does not matter */
if (!l->matters)
if (l->object->generation == generation)
continue;
- l->object->matters_to_anchor = true;
- l->object->generation = generation;
-
- transaction_find_jobs_that_matter_to_anchor(tr, l->object, generation);
+ transaction_find_jobs_that_matter_to_anchor(l->object, generation);
}
}
LIST_FOREACH(transaction, k, j) {
- if (!job_is_anchor(k) &&
+ if (tr->anchor_job != k &&
(k->installed || job_type_is_redundant(k->type, unit_active_state(k->unit))) &&
(!k->unit->job || !job_type_is_conflicting(k->type, k->unit->job->type)))
continue;
again = false;
HASHMAP_FOREACH(j, tr->jobs, i) {
- if (j->object_list) {
+ if (tr->anchor_job == j || j->object_list) {
/* log_debug("Keeping job %s/%s because of %s/%s", */
/* j->unit->id, job_type_to_string(j->type), */
/* j->object_list->subject ? j->object_list->subject->unit->id : "root", */
log_debug("Installed new job %s/%s as %u", j->unit->id, job_type_to_string(j->type), (unsigned) j->id);
}
- assert(!tr->anchor);
-
return 0;
rollback:
* the actual list of jobs, if possible. */
/* First step: figure out which jobs matter */
- transaction_find_jobs_that_matter_to_anchor(tr, NULL, generation++);
+ transaction_find_jobs_that_matter_to_anchor(tr->anchor_job, generation++);
/* Second step: Try not to stop any running services if
* we don't have to. Don't try to reverse running
}
assert(hashmap_isempty(tr->jobs));
- assert(!tr->anchor);
return 0;
}
return j;
}
-static void transaction_job_dependency_free(Transaction *tr, JobDependency *l) {
- if (!l->subject)
- LIST_REMOVE(JobDependency, subject, tr->anchor, l);
- job_dependency_free(l);
-}
-
static void transaction_unlink_job(Transaction *tr, Job *j, bool delete_dependencies) {
assert(tr);
assert(j);
j->transaction_prev = j->transaction_next = NULL;
while (j->subject_list)
- transaction_job_dependency_free(tr, j->subject_list);
+ job_dependency_free(j->subject_list);
while (j->object_list) {
Job *other = j->object_list->matters ? j->object_list->subject : NULL;
- transaction_job_dependency_free(tr, j->object_list);
+ job_dependency_free(j->object_list);
if (other && delete_dependencies) {
log_debug("Deleting job %s/%s as dependency of job %s/%s",
bool ignore_order,
DBusError *e) {
Job *ret;
- JobDependency *l;
Iterator i;
Unit *dep;
int r;
ret->ignore_order = ret->ignore_order || ignore_order;
/* Then, add a link to the job. */
- l = job_dependency_new(by, ret, matters, conflicts);
- if (!l)
- return -ENOMEM;
-
- /* If the link has no subject job, it's the anchor link. */
- if (!by) {
- LIST_PREPEND(JobDependency, subject, tr->anchor, l);
+ if (by) {
+ if (!job_dependency_new(by, ret, matters, conflicts))
+ return -ENOMEM;
+ } else {
+ /* If the job has no parent job, it is the anchor job. */
assert(!tr->anchor_job);
tr->anchor_job = ret;
}
-
if (is_new && !ignore_requirements) {
Set *following;