1 #include "transaction.h"
2 #include "bus-errors.h"
4 static void transaction_unlink_job(Transaction
*tr
, Job
*j
, bool delete_dependencies
);
6 static void transaction_delete_job(Transaction
*tr
, Job
*j
, bool delete_dependencies
) {
10 /* Deletes one job from the transaction */
12 transaction_unlink_job(tr
, j
, delete_dependencies
);
18 static void transaction_delete_unit(Transaction
*tr
, Unit
*u
) {
21 /* Deletes all jobs associated with a certain unit from the
24 while ((j
= hashmap_get(tr
->jobs
, u
)))
25 transaction_delete_job(tr
, j
, true);
28 void transaction_abort(Transaction
*tr
) {
33 while ((j
= hashmap_first(tr
->jobs
)))
34 transaction_delete_job(tr
, j
, true);
36 assert(hashmap_isempty(tr
->jobs
));
41 static void transaction_find_jobs_that_matter_to_anchor(Transaction
*tr
, Job
*j
, unsigned generation
) {
46 /* A recursive sweep through the graph that marks all units
47 * that matter to the anchor job, i.e. are directly or
48 * indirectly a dependency of the anchor job via paths that
49 * are fully marked as mattering. */
56 LIST_FOREACH(subject
, l
, l
) {
58 /* This link does not matter */
62 /* This unit has already been marked */
63 if (l
->object
->generation
== generation
)
66 l
->object
->matters_to_anchor
= true;
67 l
->object
->generation
= generation
;
69 transaction_find_jobs_that_matter_to_anchor(tr
, l
->object
, generation
);
73 static void transaction_merge_and_delete_job(Transaction
*tr
, Job
*j
, Job
*other
, JobType t
) {
74 JobDependency
*l
, *last
;
78 assert(j
->unit
== other
->unit
);
79 assert(!j
->installed
);
81 /* Merges 'other' into 'j' and then deletes 'other'. */
84 j
->state
= JOB_WAITING
;
85 j
->override
= j
->override
|| other
->override
;
87 j
->matters_to_anchor
= j
->matters_to_anchor
|| other
->matters_to_anchor
;
89 /* Patch us in as new owner of the JobDependency objects */
91 LIST_FOREACH(subject
, l
, other
->subject_list
) {
92 assert(l
->subject
== other
);
97 /* Merge both lists */
99 last
->subject_next
= j
->subject_list
;
101 j
->subject_list
->subject_prev
= last
;
102 j
->subject_list
= other
->subject_list
;
105 /* Patch us in as new owner of the JobDependency objects */
107 LIST_FOREACH(object
, l
, other
->object_list
) {
108 assert(l
->object
== other
);
113 /* Merge both lists */
115 last
->object_next
= j
->object_list
;
117 j
->object_list
->object_prev
= last
;
118 j
->object_list
= other
->object_list
;
121 /* Kill the other job */
122 other
->subject_list
= NULL
;
123 other
->object_list
= NULL
;
124 transaction_delete_job(tr
, other
, true);
127 static bool job_is_conflicted_by(Job
*j
) {
132 /* Returns true if this job is pulled in by a least one
133 * ConflictedBy dependency. */
135 LIST_FOREACH(object
, l
, j
->object_list
)
142 static int delete_one_unmergeable_job(Transaction
*tr
, Job
*j
) {
147 /* Tries to delete one item in the linked list
148 * j->transaction_next->transaction_next->... that conflicts
149 * with another one, in an attempt to make an inconsistent
150 * transaction work. */
152 /* We rely here on the fact that if a merged with b does not
153 * merge with c, either a or b merge with c neither */
154 LIST_FOREACH(transaction
, j
, j
)
155 LIST_FOREACH(transaction
, k
, j
->transaction_next
) {
158 /* Is this one mergeable? Then skip it */
159 if (job_type_is_mergeable(j
->type
, k
->type
))
162 /* Ok, we found two that conflict, let's see if we can
163 * drop one of them */
164 if (!j
->matters_to_anchor
&& !k
->matters_to_anchor
) {
166 /* Both jobs don't matter, so let's
167 * find the one that is smarter to
168 * remove. Let's think positive and
169 * rather remove stops then starts --
170 * except if something is being
171 * stopped because it is conflicted by
172 * another unit in which case we
173 * rather remove the start. */
175 log_debug("Looking at job %s/%s conflicted_by=%s", j
->unit
->id
, job_type_to_string(j
->type
), yes_no(j
->type
== JOB_STOP
&& job_is_conflicted_by(j
)));
176 log_debug("Looking at job %s/%s conflicted_by=%s", k
->unit
->id
, job_type_to_string(k
->type
), yes_no(k
->type
== JOB_STOP
&& job_is_conflicted_by(k
)));
178 if (j
->type
== JOB_STOP
) {
180 if (job_is_conflicted_by(j
))
185 } else if (k
->type
== JOB_STOP
) {
187 if (job_is_conflicted_by(k
))
194 } else if (!j
->matters_to_anchor
)
196 else if (!k
->matters_to_anchor
)
201 /* Ok, we can drop one, so let's do so. */
202 log_debug("Fixing conflicting jobs by deleting job %s/%s", d
->unit
->id
, job_type_to_string(d
->type
));
203 transaction_delete_job(tr
, d
, true);
210 static int transaction_merge_jobs(Transaction
*tr
, DBusError
*e
) {
217 /* First step, check whether any of the jobs for one specific
218 * task conflict. If so, try to drop one of them. */
219 HASHMAP_FOREACH(j
, tr
->jobs
, i
) {
224 LIST_FOREACH(transaction
, k
, j
->transaction_next
) {
225 if (job_type_merge(&t
, k
->type
) >= 0)
228 /* OK, we could not merge all jobs for this
229 * action. Let's see if we can get rid of one
232 r
= delete_one_unmergeable_job(tr
, j
);
234 /* Ok, we managed to drop one, now
235 * let's ask our callers to call us
236 * again after garbage collecting */
239 /* We couldn't merge anything. Failure */
240 dbus_set_error(e
, BUS_ERROR_TRANSACTION_JOBS_CONFLICTING
, "Transaction contains conflicting jobs '%s' and '%s' for %s. Probably contradicting requirement dependencies configured.",
241 job_type_to_string(t
), job_type_to_string(k
->type
), k
->unit
->id
);
246 /* Second step, merge the jobs. */
247 HASHMAP_FOREACH(j
, tr
->jobs
, i
) {
251 /* Merge all transactions */
252 LIST_FOREACH(transaction
, k
, j
->transaction_next
)
253 assert_se(job_type_merge(&t
, k
->type
) == 0);
255 /* If an active job is mergeable, merge it too */
257 job_type_merge(&t
, j
->unit
->job
->type
); /* Might fail. Which is OK */
259 while ((k
= j
->transaction_next
)) {
261 transaction_merge_and_delete_job(tr
, k
, j
, t
);
264 transaction_merge_and_delete_job(tr
, j
, k
, t
);
267 if (j
->unit
->job
&& !j
->installed
)
268 transaction_merge_and_delete_job(tr
, j
, j
->unit
->job
, t
);
270 assert(!j
->transaction_next
);
271 assert(!j
->transaction_prev
);
277 static void transaction_drop_redundant(Transaction
*tr
) {
282 /* Goes through the transaction and removes all jobs that are
291 HASHMAP_FOREACH(j
, tr
->jobs
, i
) {
292 bool changes_something
= false;
295 LIST_FOREACH(transaction
, k
, j
) {
297 if (!job_is_anchor(k
) &&
298 (k
->installed
|| job_type_is_redundant(k
->type
, unit_active_state(k
->unit
))) &&
299 (!k
->unit
->job
|| !job_type_is_conflicting(k
->type
, k
->unit
->job
->type
)))
302 changes_something
= true;
306 if (changes_something
)
309 /* log_debug("Found redundant job %s/%s, dropping.", j->unit->id, job_type_to_string(j->type)); */
310 transaction_delete_job(tr
, j
, false);
318 static bool unit_matters_to_anchor(Unit
*u
, Job
*j
) {
320 assert(!j
->transaction_prev
);
322 /* Checks whether at least one of the jobs for this unit
323 * matters to the anchor. */
325 LIST_FOREACH(transaction
, j
, j
)
326 if (j
->matters_to_anchor
)
332 static int transaction_verify_order_one(Transaction
*tr
, Job
*j
, Job
*from
, unsigned generation
, DBusError
*e
) {
339 assert(!j
->transaction_prev
);
341 /* Does a recursive sweep through the ordering graph, looking
342 * for a cycle. If we find cycle we try to break it. */
344 /* Have we seen this before? */
345 if (j
->generation
== generation
) {
348 /* If the marker is NULL we have been here already and
349 * decided the job was loop-free from here. Hence
350 * shortcut things and return right-away. */
354 /* So, the marker is not NULL and we already have been
355 * here. We have a cycle. Let's try to break it. We go
356 * backwards in our path and try to find a suitable
357 * job to remove. We use the marker to find our way
358 * back, since smart how we are we stored our way back
360 log_warning("Found ordering cycle on %s/%s", j
->unit
->id
, job_type_to_string(j
->type
));
363 for (k
= from
; k
; k
= ((k
->generation
== generation
&& k
->marker
!= k
) ? k
->marker
: NULL
)) {
365 log_info("Walked on cycle path to %s/%s", k
->unit
->id
, job_type_to_string(k
->type
));
369 !unit_matters_to_anchor(k
->unit
, k
)) {
370 /* Ok, we can drop this one, so let's
375 /* Check if this in fact was the beginning of
383 log_warning("Breaking ordering cycle by deleting job %s/%s", delete->unit
->id
, job_type_to_string(delete->type
));
384 transaction_delete_unit(tr
, delete->unit
);
388 log_error("Unable to break cycle");
390 dbus_set_error(e
, BUS_ERROR_TRANSACTION_ORDER_IS_CYCLIC
, "Transaction order is cyclic. See system logs for details.");
394 /* Make the marker point to where we come from, so that we can
395 * find our way backwards if we want to break a cycle. We use
396 * a special marker for the beginning: we point to
398 j
->marker
= from
? from
: j
;
399 j
->generation
= generation
;
401 /* We assume that the the dependencies are bidirectional, and
402 * hence can ignore UNIT_AFTER */
403 SET_FOREACH(u
, j
->unit
->dependencies
[UNIT_BEFORE
], i
) {
406 /* Is there a job for this unit? */
407 o
= hashmap_get(tr
->jobs
, u
);
409 /* Ok, there is no job for this in the
410 * transaction, but maybe there is already one
417 r
= transaction_verify_order_one(tr
, o
, j
, generation
, e
);
422 /* Ok, let's backtrack, and remember that this entry is not on
423 * our path anymore. */
429 static int transaction_verify_order(Transaction
*tr
, unsigned *generation
, DBusError
*e
) {
438 /* Check if the ordering graph is cyclic. If it is, try to fix
439 * that up by dropping one of the jobs. */
443 HASHMAP_FOREACH(j
, tr
->jobs
, i
)
444 if ((r
= transaction_verify_order_one(tr
, j
, NULL
, g
, e
)) < 0)
450 static void transaction_collect_garbage(Transaction
*tr
) {
455 /* Drop jobs that are not required by any other job */
463 HASHMAP_FOREACH(j
, tr
->jobs
, i
) {
464 if (j
->object_list
) {
465 /* log_debug("Keeping job %s/%s because of %s/%s", */
466 /* j->unit->id, job_type_to_string(j->type), */
467 /* j->object_list->subject ? j->object_list->subject->unit->id : "root", */
468 /* j->object_list->subject ? job_type_to_string(j->object_list->subject->type) : "root"); */
472 /* log_debug("Garbage collecting job %s/%s", j->unit->id, job_type_to_string(j->type)); */
473 transaction_delete_job(tr
, j
, true);
481 static int transaction_is_destructive(Transaction
*tr
, DBusError
*e
) {
487 /* Checks whether applying this transaction means that
488 * existing jobs would be replaced */
490 HASHMAP_FOREACH(j
, tr
->jobs
, i
) {
493 assert(!j
->transaction_prev
);
494 assert(!j
->transaction_next
);
498 !job_type_is_superset(j
->type
, j
->unit
->job
->type
)) {
500 dbus_set_error(e
, BUS_ERROR_TRANSACTION_IS_DESTRUCTIVE
, "Transaction is destructive.");
508 static void transaction_minimize_impact(Transaction
*tr
) {
512 /* Drops all unnecessary jobs that reverse already active jobs
513 * or that stop a running service. */
521 HASHMAP_FOREACH(j
, tr
->jobs
, i
) {
522 LIST_FOREACH(transaction
, j
, j
) {
523 bool stops_running_service
, changes_existing_job
;
525 /* If it matters, we shouldn't drop it */
526 if (j
->matters_to_anchor
)
529 /* Would this stop a running service?
530 * Would this change an existing job?
531 * If so, let's drop this entry */
533 stops_running_service
=
534 j
->type
== JOB_STOP
&& UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(j
->unit
));
536 changes_existing_job
=
538 job_type_is_conflicting(j
->type
, j
->unit
->job
->type
);
540 if (!stops_running_service
&& !changes_existing_job
)
543 if (stops_running_service
)
544 log_debug("%s/%s would stop a running service.", j
->unit
->id
, job_type_to_string(j
->type
));
546 if (changes_existing_job
)
547 log_debug("%s/%s would change existing job.", j
->unit
->id
, job_type_to_string(j
->type
));
549 /* Ok, let's get rid of this */
550 log_debug("Deleting %s/%s to minimize impact.", j
->unit
->id
, job_type_to_string(j
->type
));
552 transaction_delete_job(tr
, j
, true);
564 static int transaction_apply(Transaction
*tr
, Manager
*m
, JobMode mode
) {
569 /* Moves the transaction jobs to the set of active jobs */
571 if (mode
== JOB_ISOLATE
) {
573 /* When isolating first kill all installed jobs which
574 * aren't part of the new transaction */
576 HASHMAP_FOREACH(j
, m
->jobs
, i
) {
577 assert(j
->installed
);
579 if (hashmap_get(tr
->jobs
, j
->unit
))
582 /* 'j' itself is safe to remove, but if other jobs
583 are invalidated recursively, our iterator may become
584 invalid and we need to start over. */
585 if (job_finish_and_invalidate(j
, JOB_CANCELED
) > 0)
590 HASHMAP_FOREACH(j
, tr
->jobs
, i
) {
592 assert(!j
->transaction_prev
);
593 assert(!j
->transaction_next
);
598 r
= hashmap_put(m
->jobs
, UINT32_TO_PTR(j
->id
), j
);
603 while ((j
= hashmap_steal_first(tr
->jobs
))) {
606 /* log_debug("Skipping already installed job %s/%s as %u", j->unit->id, job_type_to_string(j->type), (unsigned) j->id); */
618 m
->n_installed_jobs
++;
620 /* We're fully installed. Now let's free data we don't
623 assert(!j
->transaction_next
);
624 assert(!j
->transaction_prev
);
626 /* Clean the job dependencies */
627 transaction_unlink_job(tr
, j
, false);
629 job_add_to_run_queue(j
);
630 job_add_to_dbus_queue(j
);
633 log_debug("Installed new job %s/%s as %u", j
->unit
->id
, job_type_to_string(j
->type
), (unsigned) j
->id
);
642 HASHMAP_FOREACH(j
, tr
->jobs
, i
) {
646 hashmap_remove(m
->jobs
, UINT32_TO_PTR(j
->id
));
652 int transaction_activate(Transaction
*tr
, Manager
*m
, JobMode mode
, DBusError
*e
) {
654 unsigned generation
= 1;
658 /* This applies the changes recorded in tr->jobs to
659 * the actual list of jobs, if possible. */
661 /* First step: figure out which jobs matter */
662 transaction_find_jobs_that_matter_to_anchor(tr
, NULL
, generation
++);
664 /* Second step: Try not to stop any running services if
665 * we don't have to. Don't try to reverse running
666 * jobs if we don't have to. */
667 if (mode
== JOB_FAIL
)
668 transaction_minimize_impact(tr
);
670 /* Third step: Drop redundant jobs */
671 transaction_drop_redundant(tr
);
674 /* Fourth step: Let's remove unneeded jobs that might
676 if (mode
!= JOB_ISOLATE
)
677 transaction_collect_garbage(tr
);
679 /* Fifth step: verify order makes sense and correct
680 * cycles if necessary and possible */
681 r
= transaction_verify_order(tr
, &generation
, e
);
686 log_warning("Requested transaction contains an unfixable cyclic ordering dependency: %s", bus_error(e
, r
));
690 /* Let's see if the resulting transaction ordering
691 * graph is still cyclic... */
695 /* Sixth step: let's drop unmergeable entries if
696 * necessary and possible, merge entries we can
698 r
= transaction_merge_jobs(tr
, e
);
703 log_warning("Requested transaction contains unmergeable jobs: %s", bus_error(e
, r
));
707 /* Seventh step: an entry got dropped, let's garbage
708 * collect its dependencies. */
709 if (mode
!= JOB_ISOLATE
)
710 transaction_collect_garbage(tr
);
712 /* Let's see if the resulting transaction still has
713 * unmergeable entries ... */
716 /* Eights step: Drop redundant jobs again, if the merging now allows us to drop more. */
717 transaction_drop_redundant(tr
);
719 /* Ninth step: check whether we can actually apply this */
720 if (mode
== JOB_FAIL
) {
721 r
= transaction_is_destructive(tr
, e
);
723 log_notice("Requested transaction contradicts existing jobs: %s", bus_error(e
, r
));
728 /* Tenth step: apply changes */
729 r
= transaction_apply(tr
, m
, mode
);
731 log_warning("Failed to apply transaction: %s", strerror(-r
));
735 assert(hashmap_isempty(tr
->jobs
));
741 static Job
* transaction_add_one_job(Transaction
*tr
, JobType type
, Unit
*unit
, bool override
, bool *is_new
) {
747 /* Looks for an existing prospective job and returns that. If
748 * it doesn't exist it is created and added to the prospective
751 f
= hashmap_get(tr
->jobs
, unit
);
753 LIST_FOREACH(transaction
, j
, f
) {
754 assert(j
->unit
== unit
);
756 if (j
->type
== type
) {
763 j
= job_new(unit
, type
);
769 j
->matters_to_anchor
= false;
770 j
->override
= override
;
772 LIST_PREPEND(Job
, transaction
, f
, j
);
774 if (hashmap_replace(tr
->jobs
, unit
, f
) < 0) {
775 LIST_REMOVE(Job
, transaction
, f
, j
);
783 /* log_debug("Added job %s/%s to transaction.", unit->id, job_type_to_string(type)); */
788 static void transaction_job_dependency_free(Transaction
*tr
, JobDependency
*l
) {
790 LIST_REMOVE(JobDependency
, subject
, tr
->anchor
, l
);
791 job_dependency_free(l
);
794 static void transaction_unlink_job(Transaction
*tr
, Job
*j
, bool delete_dependencies
) {
798 if (j
->transaction_prev
)
799 j
->transaction_prev
->transaction_next
= j
->transaction_next
;
800 else if (j
->transaction_next
)
801 hashmap_replace(tr
->jobs
, j
->unit
, j
->transaction_next
);
803 hashmap_remove_value(tr
->jobs
, j
->unit
, j
);
805 if (j
->transaction_next
)
806 j
->transaction_next
->transaction_prev
= j
->transaction_prev
;
808 j
->transaction_prev
= j
->transaction_next
= NULL
;
810 while (j
->subject_list
)
811 transaction_job_dependency_free(tr
, j
->subject_list
);
813 while (j
->object_list
) {
814 Job
*other
= j
->object_list
->matters
? j
->object_list
->subject
: NULL
;
816 transaction_job_dependency_free(tr
, j
->object_list
);
818 if (other
&& delete_dependencies
) {
819 log_debug("Deleting job %s/%s as dependency of job %s/%s",
820 other
->unit
->id
, job_type_to_string(other
->type
),
821 j
->unit
->id
, job_type_to_string(j
->type
));
822 transaction_delete_job(tr
, other
, delete_dependencies
);
827 int transaction_add_job_and_dependencies(
835 bool ignore_requirements
,
846 assert(type
< _JOB_TYPE_MAX
);
849 /* log_debug("Pulling in %s/%s from %s/%s", */
850 /* unit->id, job_type_to_string(type), */
851 /* by ? by->unit->id : "NA", */
852 /* by ? job_type_to_string(by->type) : "NA"); */
854 if (unit
->load_state
!= UNIT_LOADED
&&
855 unit
->load_state
!= UNIT_ERROR
&&
856 unit
->load_state
!= UNIT_MASKED
) {
857 dbus_set_error(e
, BUS_ERROR_LOAD_FAILED
, "Unit %s is not loaded properly.", unit
->id
);
861 if (type
!= JOB_STOP
&& unit
->load_state
== UNIT_ERROR
) {
862 dbus_set_error(e
, BUS_ERROR_LOAD_FAILED
,
863 "Unit %s failed to load: %s. "
864 "See system logs and 'systemctl status %s' for details.",
866 strerror(-unit
->load_error
),
871 if (type
!= JOB_STOP
&& unit
->load_state
== UNIT_MASKED
) {
872 dbus_set_error(e
, BUS_ERROR_MASKED
, "Unit %s is masked.", unit
->id
);
876 if (!unit_job_is_applicable(unit
, type
)) {
877 dbus_set_error(e
, BUS_ERROR_JOB_TYPE_NOT_APPLICABLE
, "Job type %s is not applicable for unit %s.", job_type_to_string(type
), unit
->id
);
881 /* First add the job. */
882 ret
= transaction_add_one_job(tr
, type
, unit
, override
, &is_new
);
886 ret
->ignore_order
= ret
->ignore_order
|| ignore_order
;
888 /* Then, add a link to the job. */
889 l
= job_dependency_new(by
, ret
, matters
, conflicts
);
893 /* If the link has no subject job, it's the anchor link. */
895 LIST_PREPEND(JobDependency
, subject
, tr
->anchor
, l
);
896 assert(!tr
->anchor_job
);
897 tr
->anchor_job
= ret
;
900 if (is_new
&& !ignore_requirements
) {
903 /* If we are following some other unit, make sure we
904 * add all dependencies of everybody following. */
905 if (unit_following_set(ret
->unit
, &following
) > 0) {
906 SET_FOREACH(dep
, following
, i
) {
907 r
= transaction_add_job_and_dependencies(tr
, type
, dep
, ret
, false, override
, false, false, ignore_order
, e
);
909 log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep
->id
, bus_error(e
, r
));
919 /* Finally, recursively add in all dependencies. */
920 if (type
== JOB_START
|| type
== JOB_RELOAD_OR_START
) {
921 SET_FOREACH(dep
, ret
->unit
->dependencies
[UNIT_REQUIRES
], i
) {
922 r
= transaction_add_job_and_dependencies(tr
, JOB_START
, dep
, ret
, true, override
, false, false, ignore_order
, e
);
932 SET_FOREACH(dep
, ret
->unit
->dependencies
[UNIT_BIND_TO
], i
) {
933 r
= transaction_add_job_and_dependencies(tr
, JOB_START
, dep
, ret
, true, override
, false, false, ignore_order
, e
);
943 SET_FOREACH(dep
, ret
->unit
->dependencies
[UNIT_REQUIRES_OVERRIDABLE
], i
) {
944 r
= transaction_add_job_and_dependencies(tr
, JOB_START
, dep
, ret
, !override
, override
, false, false, ignore_order
, e
);
946 log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep
->id
, bus_error(e
, r
));
953 SET_FOREACH(dep
, ret
->unit
->dependencies
[UNIT_WANTS
], i
) {
954 r
= transaction_add_job_and_dependencies(tr
, JOB_START
, dep
, ret
, false, false, false, false, ignore_order
, e
);
956 log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep
->id
, bus_error(e
, r
));
963 SET_FOREACH(dep
, ret
->unit
->dependencies
[UNIT_REQUISITE
], i
) {
964 r
= transaction_add_job_and_dependencies(tr
, JOB_VERIFY_ACTIVE
, dep
, ret
, true, override
, false, false, ignore_order
, e
);
974 SET_FOREACH(dep
, ret
->unit
->dependencies
[UNIT_REQUISITE_OVERRIDABLE
], i
) {
975 r
= transaction_add_job_and_dependencies(tr
, JOB_VERIFY_ACTIVE
, dep
, ret
, !override
, override
, false, false, ignore_order
, e
);
977 log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep
->id
, bus_error(e
, r
));
984 SET_FOREACH(dep
, ret
->unit
->dependencies
[UNIT_CONFLICTS
], i
) {
985 r
= transaction_add_job_and_dependencies(tr
, JOB_STOP
, dep
, ret
, true, override
, true, false, ignore_order
, e
);
995 SET_FOREACH(dep
, ret
->unit
->dependencies
[UNIT_CONFLICTED_BY
], i
) {
996 r
= transaction_add_job_and_dependencies(tr
, JOB_STOP
, dep
, ret
, false, override
, false, false, ignore_order
, e
);
998 log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep
->id
, bus_error(e
, r
));
1007 if (type
== JOB_STOP
|| type
== JOB_RESTART
|| type
== JOB_TRY_RESTART
) {
1009 SET_FOREACH(dep
, ret
->unit
->dependencies
[UNIT_REQUIRED_BY
], i
) {
1010 r
= transaction_add_job_and_dependencies(tr
, type
, dep
, ret
, true, override
, false, false, ignore_order
, e
);
1020 SET_FOREACH(dep
, ret
->unit
->dependencies
[UNIT_BOUND_BY
], i
) {
1021 r
= transaction_add_job_and_dependencies(tr
, type
, dep
, ret
, true, override
, false, false, ignore_order
, e
);
1032 if (type
== JOB_RELOAD
|| type
== JOB_RELOAD_OR_START
) {
1034 SET_FOREACH(dep
, ret
->unit
->dependencies
[UNIT_PROPAGATE_RELOAD_TO
], i
) {
1035 r
= transaction_add_job_and_dependencies(tr
, JOB_RELOAD
, dep
, ret
, false, override
, false, false, ignore_order
, e
);
1037 log_warning("Cannot add dependency reload job for unit %s, ignoring: %s", dep
->id
, bus_error(e
, r
));
1045 /* JOB_VERIFY_STARTED, JOB_RELOAD require no dependency handling */
1054 int transaction_add_isolate_jobs(Transaction
*tr
, Manager
*m
) {
1063 HASHMAP_FOREACH_KEY(u
, k
, m
->units
, i
) {
1065 /* ignore aliases */
1069 if (u
->ignore_on_isolate
)
1072 /* No need to stop inactive jobs */
1073 if (UNIT_IS_INACTIVE_OR_FAILED(unit_active_state(u
)) && !u
->job
)
1076 /* Is there already something listed for this? */
1077 if (hashmap_get(tr
->jobs
, u
))
1080 r
= transaction_add_job_and_dependencies(tr
, JOB_STOP
, u
, tr
->anchor_job
, true, false, false, false, false, NULL
);
1082 log_warning("Cannot add isolate job for unit %s, ignoring: %s", u
->id
, strerror(-r
));
1088 Transaction
*transaction_new(void) {
1091 tr
= new0(Transaction
, 1);
1095 tr
->jobs
= hashmap_new(trivial_hash_func
, trivial_compare_func
);
1104 void transaction_free(Transaction
*tr
) {
1105 assert(hashmap_isempty(tr
->jobs
));
1106 hashmap_free(tr
->jobs
);