1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include "transaction.h"
23 #include "bus-errors.h"
25 static void transaction_unlink_job(Transaction *tr, Job *j, bool delete_dependencies);
27 static void transaction_delete_job(Transaction *tr, Job *j, bool delete_dependencies) {
31 /* Deletes one job from the transaction */
33 transaction_unlink_job(tr, j, delete_dependencies);
38 static void transaction_delete_unit(Transaction *tr, Unit *u) {
41 /* Deletes all jobs associated with a certain unit from the
44 while ((j = hashmap_get(tr->jobs, u)))
45 transaction_delete_job(tr, j, true);
48 void transaction_abort(Transaction *tr) {
53 while ((j = hashmap_first(tr->jobs)))
54 transaction_delete_job(tr, j, false);
56 assert(hashmap_isempty(tr->jobs));
59 static void transaction_find_jobs_that_matter_to_anchor(Job *j, unsigned generation) {
62 /* A recursive sweep through the graph that marks all units
63 * that matter to the anchor job, i.e. are directly or
64 * indirectly a dependency of the anchor job via paths that
65 * are fully marked as mattering. */
67 j->matters_to_anchor = true;
68 j->generation = generation;
70 LIST_FOREACH(subject, l, j->subject_list) {
72 /* This link does not matter */
76 /* This unit has already been marked */
77 if (l->object->generation == generation)
80 transaction_find_jobs_that_matter_to_anchor(l->object, generation);
84 static void transaction_merge_and_delete_job(Transaction *tr, Job *j, Job *other, JobType t) {
85 JobDependency *l, *last;
89 assert(j->unit == other->unit);
90 assert(!j->installed);
92 /* Merges 'other' into 'j' and then deletes 'other'. */
95 j->state = JOB_WAITING;
96 j->override = j->override || other->override;
98 j->matters_to_anchor = j->matters_to_anchor || other->matters_to_anchor;
100 /* Patch us in as new owner of the JobDependency objects */
102 LIST_FOREACH(subject, l, other->subject_list) {
103 assert(l->subject == other);
108 /* Merge both lists */
110 last->subject_next = j->subject_list;
112 j->subject_list->subject_prev = last;
113 j->subject_list = other->subject_list;
116 /* Patch us in as new owner of the JobDependency objects */
118 LIST_FOREACH(object, l, other->object_list) {
119 assert(l->object == other);
124 /* Merge both lists */
126 last->object_next = j->object_list;
128 j->object_list->object_prev = last;
129 j->object_list = other->object_list;
132 /* Kill the other job */
133 other->subject_list = NULL;
134 other->object_list = NULL;
135 transaction_delete_job(tr, other, true);
138 static bool job_is_conflicted_by(Job *j) {
143 /* Returns true if this job is pulled in by a least one
144 * ConflictedBy dependency. */
146 LIST_FOREACH(object, l, j->object_list)
153 static int delete_one_unmergeable_job(Transaction *tr, Job *j) {
158 /* Tries to delete one item in the linked list
159 * j->transaction_next->transaction_next->... that conflicts
160 * with another one, in an attempt to make an inconsistent
161 * transaction work. */
163 /* We rely here on the fact that if a merged with b does not
164 * merge with c, either a or b merge with c neither */
165 LIST_FOREACH(transaction, j, j)
166 LIST_FOREACH(transaction, k, j->transaction_next) {
169 /* Is this one mergeable? Then skip it */
170 if (job_type_is_mergeable(j->type, k->type))
173 /* Ok, we found two that conflict, let's see if we can
174 * drop one of them */
175 if (!j->matters_to_anchor && !k->matters_to_anchor) {
177 /* Both jobs don't matter, so let's
178 * find the one that is smarter to
179 * remove. Let's think positive and
180 * rather remove stops then starts --
181 * except if something is being
182 * stopped because it is conflicted by
183 * another unit in which case we
184 * rather remove the start. */
186 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)));
187 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)));
189 if (j->type == JOB_STOP) {
191 if (job_is_conflicted_by(j))
196 } else if (k->type == JOB_STOP) {
198 if (job_is_conflicted_by(k))
205 } else if (!j->matters_to_anchor)
207 else if (!k->matters_to_anchor)
212 /* Ok, we can drop one, so let's do so. */
213 log_debug("Fixing conflicting jobs by deleting job %s/%s", d->unit->id, job_type_to_string(d->type));
214 transaction_delete_job(tr, d, true);
221 static int transaction_merge_jobs(Transaction *tr, DBusError *e) {
228 /* First step, check whether any of the jobs for one specific
229 * task conflict. If so, try to drop one of them. */
230 HASHMAP_FOREACH(j, tr->jobs, i) {
235 LIST_FOREACH(transaction, k, j->transaction_next) {
236 if (job_type_merge(&t, k->type) >= 0)
239 /* OK, we could not merge all jobs for this
240 * action. Let's see if we can get rid of one
243 r = delete_one_unmergeable_job(tr, j);
245 /* Ok, we managed to drop one, now
246 * let's ask our callers to call us
247 * again after garbage collecting */
250 /* We couldn't merge anything. Failure */
251 dbus_set_error(e, BUS_ERROR_TRANSACTION_JOBS_CONFLICTING, "Transaction contains conflicting jobs '%s' and '%s' for %s. Probably contradicting requirement dependencies configured.",
252 job_type_to_string(t), job_type_to_string(k->type), k->unit->id);
257 /* Second step, merge the jobs. */
258 HASHMAP_FOREACH(j, tr->jobs, i) {
262 /* Merge all transactions */
263 LIST_FOREACH(transaction, k, j->transaction_next)
264 assert_se(job_type_merge(&t, k->type) == 0);
266 while ((k = j->transaction_next)) {
267 if (tr->anchor_job == k) {
268 transaction_merge_and_delete_job(tr, k, j, t);
271 transaction_merge_and_delete_job(tr, j, k, t);
274 assert(!j->transaction_next);
275 assert(!j->transaction_prev);
281 static void transaction_drop_redundant(Transaction *tr) {
285 /* Goes through the transaction and removes all jobs of the units
286 * whose jobs are all noops. If not all of a unit's jobs are
287 * redundant, they are kept. */
292 HASHMAP_FOREACH(j, tr->jobs, i) {
295 LIST_FOREACH(transaction, k, j) {
297 if (tr->anchor_job == k ||
298 !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)))
303 /* log_debug("Found redundant job %s/%s, dropping.", j->unit->id, job_type_to_string(j->type)); */
304 transaction_delete_job(tr, j, false);
310 static bool unit_matters_to_anchor(Unit *u, Job *j) {
312 assert(!j->transaction_prev);
314 /* Checks whether at least one of the jobs for this unit
315 * matters to the anchor. */
317 LIST_FOREACH(transaction, j, j)
318 if (j->matters_to_anchor)
324 static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsigned generation, DBusError *e) {
331 assert(!j->transaction_prev);
333 /* Does a recursive sweep through the ordering graph, looking
334 * for a cycle. If we find cycle we try to break it. */
336 /* Have we seen this before? */
337 if (j->generation == generation) {
340 /* If the marker is NULL we have been here already and
341 * decided the job was loop-free from here. Hence
342 * shortcut things and return right-away. */
346 /* So, the marker is not NULL and we already have been
347 * here. We have a cycle. Let's try to break it. We go
348 * backwards in our path and try to find a suitable
349 * job to remove. We use the marker to find our way
350 * back, since smart how we are we stored our way back
352 log_warning("Found ordering cycle on %s/%s", j->unit->id, job_type_to_string(j->type));
355 for (k = from; k; k = ((k->generation == generation && k->marker != k) ? k->marker : NULL)) {
357 log_info("Walked on cycle path to %s/%s", k->unit->id, job_type_to_string(k->type));
360 !unit_matters_to_anchor(k->unit, k)) {
361 /* Ok, we can drop this one, so let's
366 /* Check if this in fact was the beginning of
374 log_warning("Breaking ordering cycle by deleting job %s/%s", delete->unit->id, job_type_to_string(delete->type));
375 transaction_delete_unit(tr, delete->unit);
379 log_error("Unable to break cycle");
381 dbus_set_error(e, BUS_ERROR_TRANSACTION_ORDER_IS_CYCLIC, "Transaction order is cyclic. See system logs for details.");
385 /* Make the marker point to where we come from, so that we can
386 * find our way backwards if we want to break a cycle. We use
387 * a special marker for the beginning: we point to
389 j->marker = from ? from : j;
390 j->generation = generation;
392 /* We assume that the the dependencies are bidirectional, and
393 * hence can ignore UNIT_AFTER */
394 SET_FOREACH(u, j->unit->dependencies[UNIT_BEFORE], i) {
397 /* Is there a job for this unit? */
398 o = hashmap_get(tr->jobs, u);
400 /* Ok, there is no job for this in the
401 * transaction, but maybe there is already one
408 r = transaction_verify_order_one(tr, o, j, generation, e);
413 /* Ok, let's backtrack, and remember that this entry is not on
414 * our path anymore. */
420 static int transaction_verify_order(Transaction *tr, unsigned *generation, DBusError *e) {
429 /* Check if the ordering graph is cyclic. If it is, try to fix
430 * that up by dropping one of the jobs. */
434 HASHMAP_FOREACH(j, tr->jobs, i)
435 if ((r = transaction_verify_order_one(tr, j, NULL, g, e)) < 0)
441 static void transaction_collect_garbage(Transaction *tr) {
447 /* Drop jobs that are not required by any other job */
450 HASHMAP_FOREACH(j, tr->jobs, i) {
451 if (tr->anchor_job == j || j->object_list) {
452 /* log_debug("Keeping job %s/%s because of %s/%s", */
453 /* j->unit->id, job_type_to_string(j->type), */
454 /* j->object_list->subject ? j->object_list->subject->unit->id : "root", */
455 /* j->object_list->subject ? job_type_to_string(j->object_list->subject->type) : "root"); */
459 /* log_debug("Garbage collecting job %s/%s", j->unit->id, job_type_to_string(j->type)); */
460 transaction_delete_job(tr, j, true);
465 static int transaction_is_destructive(Transaction *tr, DBusError *e) {
471 /* Checks whether applying this transaction means that
472 * existing jobs would be replaced */
474 HASHMAP_FOREACH(j, tr->jobs, i) {
477 assert(!j->transaction_prev);
478 assert(!j->transaction_next);
481 !job_type_is_superset(j->type, j->unit->job->type)) {
483 dbus_set_error(e, BUS_ERROR_TRANSACTION_IS_DESTRUCTIVE, "Transaction is destructive.");
491 static void transaction_minimize_impact(Transaction *tr) {
497 /* Drops all unnecessary jobs that reverse already active jobs
498 * or that stop a running service. */
501 HASHMAP_FOREACH(j, tr->jobs, i) {
502 LIST_FOREACH(transaction, j, j) {
503 bool stops_running_service, changes_existing_job;
505 /* If it matters, we shouldn't drop it */
506 if (j->matters_to_anchor)
509 /* Would this stop a running service?
510 * Would this change an existing job?
511 * If so, let's drop this entry */
513 stops_running_service =
514 j->type == JOB_STOP && UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(j->unit));
516 changes_existing_job =
518 job_type_is_conflicting(j->type, j->unit->job->type);
520 if (!stops_running_service && !changes_existing_job)
523 if (stops_running_service)
524 log_debug("%s/%s would stop a running service.", j->unit->id, job_type_to_string(j->type));
526 if (changes_existing_job)
527 log_debug("%s/%s would change existing job.", j->unit->id, job_type_to_string(j->type));
529 /* Ok, let's get rid of this */
530 log_debug("Deleting %s/%s to minimize impact.", j->unit->id, job_type_to_string(j->type));
532 transaction_delete_job(tr, j, true);
538 static int transaction_apply(Transaction *tr, Manager *m, JobMode mode) {
543 /* Moves the transaction jobs to the set of active jobs */
545 if (mode == JOB_ISOLATE) {
547 /* When isolating first kill all installed jobs which
548 * aren't part of the new transaction */
549 HASHMAP_FOREACH(j, m->jobs, i) {
550 assert(j->installed);
552 if (hashmap_get(tr->jobs, j->unit))
555 /* Not invalidating recursively. Avoids triggering
556 * OnFailure= actions of dependent jobs. Also avoids
557 * invalidating our iterator. */
558 job_finish_and_invalidate(j, JOB_CANCELED, false);
562 HASHMAP_FOREACH(j, tr->jobs, i) {
564 assert(!j->transaction_prev);
565 assert(!j->transaction_next);
567 r = hashmap_put(m->jobs, UINT32_TO_PTR(j->id), j);
572 while ((j = hashmap_steal_first(tr->jobs))) {
575 /* Clean the job dependencies */
576 transaction_unlink_job(tr, j, false);
578 installed_job = job_install(j);
579 if (installed_job != j) {
580 /* j has been merged into a previously installed job */
581 if (tr->anchor_job == j)
582 tr->anchor_job = installed_job;
583 hashmap_remove(m->jobs, UINT32_TO_PTR(j->id));
588 job_add_to_run_queue(j);
589 job_add_to_dbus_queue(j);
597 HASHMAP_FOREACH(j, tr->jobs, i)
598 hashmap_remove(m->jobs, UINT32_TO_PTR(j->id));
603 int transaction_activate(Transaction *tr, Manager *m, JobMode mode, DBusError *e) {
607 unsigned generation = 1;
611 /* This applies the changes recorded in tr->jobs to
612 * the actual list of jobs, if possible. */
614 /* Reset the generation counter of all installed jobs. The detection of cycles
615 * looks at installed jobs. If they had a non-zero generation from some previous
616 * walk of the graph, the algorithm would break. */
617 HASHMAP_FOREACH(j, m->jobs, i)
620 /* First step: figure out which jobs matter */
621 transaction_find_jobs_that_matter_to_anchor(tr->anchor_job, generation++);
623 /* Second step: Try not to stop any running services if
624 * we don't have to. Don't try to reverse running
625 * jobs if we don't have to. */
626 if (mode == JOB_FAIL)
627 transaction_minimize_impact(tr);
629 /* Third step: Drop redundant jobs */
630 transaction_drop_redundant(tr);
633 /* Fourth step: Let's remove unneeded jobs that might
635 if (mode != JOB_ISOLATE)
636 transaction_collect_garbage(tr);
638 /* Fifth step: verify order makes sense and correct
639 * cycles if necessary and possible */
640 r = transaction_verify_order(tr, &generation, e);
645 log_warning("Requested transaction contains an unfixable cyclic ordering dependency: %s", bus_error(e, r));
649 /* Let's see if the resulting transaction ordering
650 * graph is still cyclic... */
654 /* Sixth step: let's drop unmergeable entries if
655 * necessary and possible, merge entries we can
657 r = transaction_merge_jobs(tr, e);
662 log_warning("Requested transaction contains unmergeable jobs: %s", bus_error(e, r));
666 /* Seventh step: an entry got dropped, let's garbage
667 * collect its dependencies. */
668 if (mode != JOB_ISOLATE)
669 transaction_collect_garbage(tr);
671 /* Let's see if the resulting transaction still has
672 * unmergeable entries ... */
675 /* Eights step: Drop redundant jobs again, if the merging now allows us to drop more. */
676 transaction_drop_redundant(tr);
678 /* Ninth step: check whether we can actually apply this */
679 if (mode == JOB_FAIL) {
680 r = transaction_is_destructive(tr, e);
682 log_notice("Requested transaction contradicts existing jobs: %s", bus_error(e, r));
687 /* Tenth step: apply changes */
688 r = transaction_apply(tr, m, mode);
690 log_warning("Failed to apply transaction: %s", strerror(-r));
694 assert(hashmap_isempty(tr->jobs));
699 static Job* transaction_add_one_job(Transaction *tr, JobType type, Unit *unit, bool override, bool *is_new) {
705 /* Looks for an existing prospective job and returns that. If
706 * it doesn't exist it is created and added to the prospective
709 f = hashmap_get(tr->jobs, unit);
711 LIST_FOREACH(transaction, j, f) {
712 assert(j->unit == unit);
714 if (j->type == type) {
721 j = job_new(unit, type);
727 j->matters_to_anchor = false;
728 j->override = override;
730 LIST_PREPEND(Job, transaction, f, j);
732 if (hashmap_replace(tr->jobs, unit, f) < 0) {
733 LIST_REMOVE(Job, transaction, f, j);
741 /* log_debug("Added job %s/%s to transaction.", unit->id, job_type_to_string(type)); */
746 static void transaction_unlink_job(Transaction *tr, Job *j, bool delete_dependencies) {
750 if (j->transaction_prev)
751 j->transaction_prev->transaction_next = j->transaction_next;
752 else if (j->transaction_next)
753 hashmap_replace(tr->jobs, j->unit, j->transaction_next);
755 hashmap_remove_value(tr->jobs, j->unit, j);
757 if (j->transaction_next)
758 j->transaction_next->transaction_prev = j->transaction_prev;
760 j->transaction_prev = j->transaction_next = NULL;
762 while (j->subject_list)
763 job_dependency_free(j->subject_list);
765 while (j->object_list) {
766 Job *other = j->object_list->matters ? j->object_list->subject : NULL;
768 job_dependency_free(j->object_list);
770 if (other && delete_dependencies) {
771 log_debug("Deleting job %s/%s as dependency of job %s/%s",
772 other->unit->id, job_type_to_string(other->type),
773 j->unit->id, job_type_to_string(j->type));
774 transaction_delete_job(tr, other, delete_dependencies);
779 int transaction_add_job_and_dependencies(
787 bool ignore_requirements,
797 assert(type < _JOB_TYPE_MAX);
800 /* log_debug("Pulling in %s/%s from %s/%s", */
801 /* unit->id, job_type_to_string(type), */
802 /* by ? by->unit->id : "NA", */
803 /* by ? job_type_to_string(by->type) : "NA"); */
805 if (unit->load_state != UNIT_LOADED &&
806 unit->load_state != UNIT_ERROR &&
807 unit->load_state != UNIT_MASKED) {
808 dbus_set_error(e, BUS_ERROR_LOAD_FAILED, "Unit %s is not loaded properly.", unit->id);
812 if (type != JOB_STOP && unit->load_state == UNIT_ERROR) {
813 dbus_set_error(e, BUS_ERROR_LOAD_FAILED,
814 "Unit %s failed to load: %s. "
815 "See system logs and 'systemctl status %s' for details.",
817 strerror(-unit->load_error),
822 if (type != JOB_STOP && unit->load_state == UNIT_MASKED) {
823 dbus_set_error(e, BUS_ERROR_MASKED, "Unit %s is masked.", unit->id);
824 return -EADDRNOTAVAIL;
827 if (!unit_job_is_applicable(unit, type)) {
828 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);
832 /* First add the job. */
833 ret = transaction_add_one_job(tr, type, unit, override, &is_new);
837 ret->ignore_order = ret->ignore_order || ignore_order;
839 /* Then, add a link to the job. */
841 if (!job_dependency_new(by, ret, matters, conflicts))
844 /* If the job has no parent job, it is the anchor job. */
845 assert(!tr->anchor_job);
846 tr->anchor_job = ret;
848 if (is_new && !ignore_requirements) {
851 /* If we are following some other unit, make sure we
852 * add all dependencies of everybody following. */
853 if (unit_following_set(ret->unit, &following) > 0) {
854 SET_FOREACH(dep, following, i) {
855 r = transaction_add_job_and_dependencies(tr, type, dep, ret, false, override, false, false, ignore_order, e);
857 log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->id, bus_error(e, r));
867 /* Finally, recursively add in all dependencies. */
868 if (type == JOB_START || type == JOB_RELOAD_OR_START || type == JOB_RESTART) {
869 SET_FOREACH(dep, ret->unit->dependencies[UNIT_REQUIRES], i) {
870 r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, true, override, false, false, ignore_order, e);
880 SET_FOREACH(dep, ret->unit->dependencies[UNIT_BIND_TO], i) {
881 r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, true, override, false, false, ignore_order, e);
891 SET_FOREACH(dep, ret->unit->dependencies[UNIT_REQUIRES_OVERRIDABLE], i) {
892 r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, !override, override, false, false, ignore_order, e);
894 log_full(r == -EADDRNOTAVAIL ? LOG_DEBUG : LOG_WARNING,
895 "Cannot add dependency job for unit %s, ignoring: %s", dep->id, bus_error(e, r));
902 SET_FOREACH(dep, ret->unit->dependencies[UNIT_WANTS], i) {
903 r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, false, false, false, false, ignore_order, e);
905 log_full(r == -EADDRNOTAVAIL ? LOG_DEBUG : LOG_WARNING,
906 "Cannot add dependency job for unit %s, ignoring: %s", dep->id, bus_error(e, r));
913 SET_FOREACH(dep, ret->unit->dependencies[UNIT_REQUISITE], i) {
914 r = transaction_add_job_and_dependencies(tr, JOB_VERIFY_ACTIVE, dep, ret, true, override, false, false, ignore_order, e);
924 SET_FOREACH(dep, ret->unit->dependencies[UNIT_REQUISITE_OVERRIDABLE], i) {
925 r = transaction_add_job_and_dependencies(tr, JOB_VERIFY_ACTIVE, dep, ret, !override, override, false, false, ignore_order, e);
927 log_full(r == -EADDRNOTAVAIL ? LOG_DEBUG : LOG_WARNING,
928 "Cannot add dependency job for unit %s, ignoring: %s", dep->id, bus_error(e, r));
935 SET_FOREACH(dep, ret->unit->dependencies[UNIT_CONFLICTS], i) {
936 r = transaction_add_job_and_dependencies(tr, JOB_STOP, dep, ret, true, override, true, false, ignore_order, e);
946 SET_FOREACH(dep, ret->unit->dependencies[UNIT_CONFLICTED_BY], i) {
947 r = transaction_add_job_and_dependencies(tr, JOB_STOP, dep, ret, false, override, false, false, ignore_order, e);
949 log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->id, bus_error(e, r));
958 if (type == JOB_STOP || type == JOB_RESTART || type == JOB_TRY_RESTART) {
960 SET_FOREACH(dep, ret->unit->dependencies[UNIT_REQUIRED_BY], i) {
961 r = transaction_add_job_and_dependencies(tr, type, dep, ret, true, override, false, false, ignore_order, e);
971 SET_FOREACH(dep, ret->unit->dependencies[UNIT_BOUND_BY], i) {
972 r = transaction_add_job_and_dependencies(tr, type, dep, ret, true, override, false, false, ignore_order, e);
983 if (type == JOB_RELOAD || type == JOB_RELOAD_OR_START) {
985 SET_FOREACH(dep, ret->unit->dependencies[UNIT_PROPAGATE_RELOAD_TO], i) {
986 r = transaction_add_job_and_dependencies(tr, JOB_RELOAD, dep, ret, false, override, false, false, ignore_order, e);
988 log_warning("Cannot add dependency reload job for unit %s, ignoring: %s", dep->id, bus_error(e, r));
996 /* JOB_VERIFY_STARTED, JOB_RELOAD require no dependency handling */
1005 int transaction_add_isolate_jobs(Transaction *tr, Manager *m) {
1014 HASHMAP_FOREACH_KEY(u, k, m->units, i) {
1016 /* ignore aliases */
1020 if (u->ignore_on_isolate)
1023 /* No need to stop inactive jobs */
1024 if (UNIT_IS_INACTIVE_OR_FAILED(unit_active_state(u)) && !u->job)
1027 /* Is there already something listed for this? */
1028 if (hashmap_get(tr->jobs, u))
1031 r = transaction_add_job_and_dependencies(tr, JOB_STOP, u, tr->anchor_job, true, false, false, false, false, NULL);
1033 log_warning("Cannot add isolate job for unit %s, ignoring: %s", u->id, strerror(-r));
1039 Transaction *transaction_new(void) {
1042 tr = new0(Transaction, 1);
1046 tr->jobs = hashmap_new(trivial_hash_func, trivial_compare_func);
1055 void transaction_free(Transaction *tr) {
1056 assert(hashmap_isempty(tr->jobs));
1057 hashmap_free(tr->jobs);