manager.c revision 1ffba6fe82d65f2a87b53a21c7927bca8176038c
d657c51f14601d0235434ffb78cf6ac0f27cc83cLennart Poettering/*-*- Mode: C; c-basic-offset: 8 -*-*/
931618d08c64083ff7b29c494f482c40a5b05608Daniel Mack if (!(m->names = hashmap_new(string_hash_func, string_compare_func)))
931618d08c64083ff7b29c494f482c40a5b05608Daniel Mack if (!(m->jobs = hashmap_new(trivial_hash_func, trivial_compare_func)))
931618d08c64083ff7b29c494f482c40a5b05608Daniel Mack if (!(m->transaction_jobs = hashmap_new(trivial_hash_func, trivial_compare_func)))
e57eaef8a187762ca92838c24b9b6460878a800cDavid Herrmann while ((j = hashmap_steal_first(m->transaction_jobs)))
e57eaef8a187762ca92838c24b9b6460878a800cDavid Herrmannstatic void transaction_delete_job(Manager *m, Job *j) {
e57eaef8a187762ca92838c24b9b6460878a800cDavid Herrmann /* Deletes one job from the transaction */
861b02ebd6ec997a6880824960ba8903bac74f7dKay Sieversstatic void transaction_delete_name(Manager *m, Name *n) {
861b02ebd6ec997a6880824960ba8903bac74f7dKay Sievers /* Deletes all jobs associated with a certain name from the
861b02ebd6ec997a6880824960ba8903bac74f7dKay Sievers * transaction */
0db83ad7334809a6605501e24bad55f3b652c072David Herrmann while ((j = hashmap_get(m->transaction_jobs, n)))
5541c88977e63215e74b7517fb33cb27e5a04f17David Herrmann while ((j = hashmap_first(m->transaction_jobs)))
0db83ad7334809a6605501e24bad55f3b652c072David Herrmannstatic void transaction_find_jobs_that_matter_to_anchor(Manager *m, Job *j, unsigned generation) {
5541c88977e63215e74b7517fb33cb27e5a04f17David Herrmann /* A recursive sweep through the graph that marks all names
0db83ad7334809a6605501e24bad55f3b652c072David Herrmann * that matter to the anchor job, i.e. are directly or
0db83ad7334809a6605501e24bad55f3b652c072David Herrmann * indirectly a dependency of the anchor job via paths that
2d1ca11270e66777c90a449096203afebc37ec9cDavid Herrmann * are fully marked as mattering. */
0db83ad7334809a6605501e24bad55f3b652c072David Herrmann for (l = j ? j->subject_list : m->transaction_anchor; l; l = l->subject_next) {
0db83ad7334809a6605501e24bad55f3b652c072David Herrmann /* This link does not matter */
5f92d24fa85d6652c4754e3b3b2a3393026bd0b9Kay Sievers /* This name has already been marked */
470e72d4081c7d0fd74666b7a45358d5ee2abee1Lennart Poettering transaction_find_jobs_that_matter_to_anchor(m, l->object, generation);
470e72d4081c7d0fd74666b7a45358d5ee2abee1Lennart Poetteringstatic void transaction_merge_and_delete_job(Manager *m, Job *j, Job *other, JobType t) {
0aee49d5fba2b2ec94e5c069d937004858a04b4fThomas Hindoe Paaboel Andersen /* Merges 'other' into 'j' and then deletes j. */
470e72d4081c7d0fd74666b7a45358d5ee2abee1Lennart Poettering j->matters_to_anchor = j->matters_to_anchor || other->matters_to_anchor;
470e72d4081c7d0fd74666b7a45358d5ee2abee1Lennart Poettering /* Patch us in as new owner of the JobDependency objects */
470e72d4081c7d0fd74666b7a45358d5ee2abee1Lennart Poettering for (l = other->subject_list; l; l = l->subject_next) {
470e72d4081c7d0fd74666b7a45358d5ee2abee1Lennart Poettering /* Merge both lists */
470e72d4081c7d0fd74666b7a45358d5ee2abee1Lennart Poettering /* Patch us in as new owner of the JobDependency objects */
470e72d4081c7d0fd74666b7a45358d5ee2abee1Lennart Poettering for (l = other->object_list; l; l = l->object_next) {
470e72d4081c7d0fd74666b7a45358d5ee2abee1Lennart Poettering /* Merge both lists */
470e72d4081c7d0fd74666b7a45358d5ee2abee1Lennart Poettering /* Kill the other job */
470e72d4081c7d0fd74666b7a45358d5ee2abee1Lennart Poetteringstatic int delete_one_unmergable_job(Manager *m, Job *j) {
b912e251812bb65bed1d545d9748f5b0918f1559Lennart Poettering /* Tries to delete one item in the linked list
b912e251812bb65bed1d545d9748f5b0918f1559Lennart Poettering * j->transaction_next->transaction_next->... that conflicts
b912e251812bb65bed1d545d9748f5b0918f1559Lennart Poettering * whith another one, in an attempt to make an inconsistent
470e72d4081c7d0fd74666b7a45358d5ee2abee1Lennart Poettering * transaction work. */
0f0467e63b0e0688ae9edb1512c1a2637d62ddb4Martin Pitt /* We rely here on the fact that if a merged with b does not
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering * merge with c, either a or b merge with c neither */
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering for (; j; j = j->transaction_next)
f7a73a2558bceffd983eb7642680e718cd981122David Herrmann for (k = j->transaction_next; k; k = k->transaction_next) {
f7a73a2558bceffd983eb7642680e718cd981122David Herrmann /* Is this one mergeable? Then skip it */
f7a73a2558bceffd983eb7642680e718cd981122David Herrmann /* Ok, we found two that conflict, let's see if we can
f7a73a2558bceffd983eb7642680e718cd981122David Herrmann * drop one of them */
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering /* Ok, we can drop one, so let's do so. */
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering log_debug("Try to fix job merging by deleting job %s", name_id(d->name));
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poetteringstatic int transaction_merge_jobs(Manager *m) {
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering /* First step, check whether any of the jobs for one specific
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering * task conflict. If so, try to drop one of them. */
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering HASHMAP_FOREACH(j, m->transaction_jobs, state) {
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering for (k = j->transaction_next; k; k = k->transaction_next) {
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering if ((r = job_type_merge(&t, k->type)) >= 0)
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering /* OK, we could not merge all jobs for this
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering * action. Let's see if we can get rid of one
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering if ((r = delete_one_unmergable_job(m, j)) >= 0)
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering /* Ok, we managed to drop one, now
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering * let's ask our callers to call us
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering * again after garbage collecting */
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering /* We couldn't merge anything. Failure */
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering /* Second step, merge the jobs. */
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering HASHMAP_FOREACH(j, m->transaction_jobs, state) {
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering for (k = j->transaction_next; k; k = k->transaction_next)
1579dd2c9b8f97e5ec4016d3928d73fea160e55aLennart Poettering assert_se(job_type_merge(&t, k->type) == 0);
1579dd2c9b8f97e5ec4016d3928d73fea160e55aLennart Poettering while ((k = j->transaction_next)) {
1579dd2c9b8f97e5ec4016d3928d73fea160e55aLennart Poettering transaction_merge_and_delete_job(m, k, j, t);
1579dd2c9b8f97e5ec4016d3928d73fea160e55aLennart Poettering transaction_merge_and_delete_job(m, j, k, t);
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poetteringstatic bool name_matters_to_anchor(Name *n, Job *j) {
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering /* Checks whether at least one of the jobs for this name
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering * matters to the anchor. */
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering for (; j; j = j->transaction_next)
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poetteringstatic int transaction_verify_order_one(Manager *m, Job *j, Job *from, unsigned generation) {
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering /* Does a recursive sweep through the ordering graph, looking
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering * for a cycle. If we find cycle we try to break it. */
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering /* Did we find a cycle? */
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering if (j->marker && j->generation == generation) {
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering /* So, we already have been here. We have a
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering * cycle. Let's try to break it. We go backwards in
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering * our path and try to find a suitable job to
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering * remove. We use the marker to find our way back,
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering * since smart how we are we stored our way back in
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering for (k = from; k; k = (k->generation == generation ? k->marker : NULL)) {
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering /* Ok, we can drop this one, so let's
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering log_debug("Breaking order cycle by deleting job %s", name_id(k->name));
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering /* Check if this in fact was the beginning of
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering * the cycle */
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering /* Make the marker point to where we come from, so that we can
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering * find our way backwards if we want to break a cycle */
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering /* We assume that the the dependencies are bidirectional, and
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering * hence can ignore NAME_AFTER */
1a2d5fbe7efa04181a2d5518bc510b84b280baf9David Herrmann SET_FOREACH(n, j->name->meta.dependencies[NAME_BEFORE], state) {
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering /* Is there a job for this name? */
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering if (!(o = hashmap_get(m->transaction_jobs, n)))
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering /* Ok, there is no job for this in the
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering * transaction, but maybe there is already one
1a2d5fbe7efa04181a2d5518bc510b84b280baf9David Herrmann * running? */
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering if ((r = transaction_verify_order_one(m, o, j, generation)) < 0)
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poetteringstatic int transaction_verify_order(Manager *m, unsigned *generation) {
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering /* Check if the ordering graph is cyclic. If it is, try to fix
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering * that up by dropping one of the jobs. */
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering HASHMAP_FOREACH(j, m->transaction_jobs, state)
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering if ((r = transaction_verify_order_one(m, j, NULL, (*generation)++)) < 0)
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poetteringstatic void transaction_collect_garbage(Manager *m) {
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering /* Drop jobs that are not required by any other job */
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering HASHMAP_FOREACH(j, m->transaction_jobs, state) {
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering log_debug("Garbage collecting job %s", name_id(j->name));
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poetteringstatic int transaction_is_destructive(Manager *m, JobMode mode) {
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering /* Checks whether applying this transaction means that
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering * existing jobs would be replaced */
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering HASHMAP_FOREACH(j, m->transaction_jobs, state)
481a0aa2c9803a62cda413b8a1d05571957bb4b5Lennart Poettering !job_type_is_superset(j->type, j->name->meta.job->type))
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poetteringstatic int transaction_apply(Manager *m, JobMode mode) {
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering /* Moves the transaction jobs to the set of active jobs */
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering HASHMAP_FOREACH(j, m->transaction_jobs, state) {
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering if ((r = hashmap_put(m->jobs, UINT32_TO_PTR(j->id), j)) < 0)
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering while ((j = hashmap_steal_first(m->transaction_jobs))) {
7edecf218e5884ec8d1549707b4c7a0572c2d93bThomas Hindoe Paaboel Andersen /* We're fully installed. Now let's free data we don't
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering * need anymore. */
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering HASHMAP_FOREACH(j, m->transaction_jobs, state) {
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering hashmap_remove(m->jobs, UINT32_TO_PTR(j->id));
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poetteringstatic int transaction_activate(Manager *m, JobMode mode) {
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering /* This applies the changes recorded in transaction_jobs to
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering * the actual list of jobs, if possible. */
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering /* First step: figure out which jobs matter */
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering transaction_find_jobs_that_matter_to_anchor(m, NULL, generation++);
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering /* Second step: Let's remove unneeded jobs that might
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering * be lurking. */
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering /* Third step: verify order makes sense and correct
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering * cycles if necessary and possible */
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering if ((r = transaction_verify_order(m, &generation)) >= 0)
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering /* Let's see if the resulting transaction ordering
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering * graph is still cyclic... */
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering /* Fourth step: let's drop unmergable entries if
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering * necessary and possible, merge entries we can
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering if ((r = transaction_merge_jobs(m)) >= 0)
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering /* Fifth step: an entry got dropped, let's garbage
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering * collect its dependencies. */
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering /* Let's see if the resulting transaction still has
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering * unmergable entries ... */
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering /* Sith step: check whether we can actually apply this */
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering if ((r = transaction_is_destructive(m, mode)) < 0)
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering /* Seventh step: apply changes */
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering if ((r = transaction_apply(m, mode)) < 0)
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering assert(hashmap_isempty(m->transaction_jobs));
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poetteringstatic Job* transaction_add_one_job(Manager *m, JobType type, Name *name, bool *is_new) {
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering /* Looks for an axisting prospective job and returns that. If
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering * it doesn't exist it is created and added to the prospective
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering * jobs list. */
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering f = hashmap_get(m->transaction_jobs, name);
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering for (j = f; j; j = j->transaction_next) {
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering if (name->meta.job && name->meta.job->type == type)
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering if ((r = hashmap_replace(m->transaction_jobs, name, j)) < 0) {
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poetteringvoid manager_transaction_unlink_job(Manager *m, Job *j) {
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering j->transaction_prev->transaction_next = j->transaction_next;
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering hashmap_replace(m->transaction_jobs, j->name, j->transaction_next);
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering hashmap_remove_value(m->transaction_jobs, j->name, j);
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering j->transaction_next->transaction_prev = j->transaction_prev;
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering j->transaction_prev = j->transaction_next = NULL;
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering Job *other = j->object_list->matters ? j->object_list->subject : NULL;
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering log_debug("Deleting job %s as dependency of job %s", name_id(other->name), name_id(j->name));
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poetteringstatic int transaction_add_job_and_dependencies(Manager *m, JobType type, Name *name, Job *by, bool matters, bool force, Job **_ret) {
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering /* First add the job. */
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering if (!(ret = transaction_add_one_job(m, type, name, &is_new)))
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering /* Then, add a link to the job. */
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering if (!job_dependency_new(by, ret, matters))
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering /* Finally, recursively add in all dependencies. */
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering if (type == JOB_START || type == JOB_RELOAD_OR_START) {
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering SET_FOREACH(dep, ret->name->meta.dependencies[NAME_REQUIRES], state)
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, true, force, NULL)) < 0)
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering SET_FOREACH(dep, ret->name->meta.dependencies[NAME_SOFT_REQUIRES], state)
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, !force, force, NULL)) < 0)
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering SET_FOREACH(dep, ret->name->meta.dependencies[NAME_WANTS], state)
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, false, force, NULL)) < 0)
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering SET_FOREACH(dep, ret->name->meta.dependencies[NAME_REQUISITE], state)
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering if ((r = transaction_add_job_and_dependencies(m, JOB_VERIFY_STARTED, dep, ret, true, force, NULL)) < 0)
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering SET_FOREACH(dep, ret->name->meta.dependencies[NAME_SOFT_REQUISITE], state)
7edecf218e5884ec8d1549707b4c7a0572c2d93bThomas Hindoe Paaboel Andersen if ((r = transaction_add_job_and_dependencies(m, JOB_VERIFY_STARTED, dep, ret, !force, force, NULL)) < 0)
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering SET_FOREACH(dep, ret->name->meta.dependencies[NAME_CONFLICTS], state)
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering if ((r = transaction_add_job_and_dependencies(m, JOB_STOP, dep, ret, true, force, NULL)) < 0)
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering } else if (type == JOB_STOP || type == JOB_RESTART || type == JOB_TRY_RESTART) {
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering SET_FOREACH(dep, ret->name->meta.dependencies[NAME_REQUIRED_BY], state)
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering if ((r = transaction_add_job_and_dependencies(m, type, dep, ret, true, force, NULL)) < 0)
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering /* JOB_VERIFY_STARTED, JOB_RELOAD require no dependency handling */
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poetteringint manager_add_job(Manager *m, JobType type, Name *name, JobMode mode, bool force, Job **_ret) {
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering if ((r = transaction_add_job_and_dependencies(m, type, name, NULL, true, force, &ret))) {
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering if ((r = transaction_activate(m, mode)) < 0)
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart PoetteringJob *manager_get_job(Manager *m, uint32_t id) {
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poettering return hashmap_get(m->jobs, UINT32_TO_PTR(id));
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart PoetteringName *manager_get_name(Manager *m, const char *name) {
615aaf412c441e67c7cad2e5ae966b03fca1fae7Lennart Poetteringstatic int dispatch_load_queue(Manager *m) {
d2c643c662e2cb3b6d1445c17c80b4b2998d5c61Lennart Poettering /* Make sure we are not run recursively */
d2c643c662e2cb3b6d1445c17c80b4b2998d5c61Lennart Poettering /* Dispatches the load queue. Takes a name from the queue and
d2c643c662e2cb3b6d1445c17c80b4b2998d5c61Lennart Poettering * tries to load its data until the queue is empty */
d2c643c662e2cb3b6d1445c17c80b4b2998d5c61Lennart Poetteringint manager_load_name(Manager *m, const char *name, Name **_ret) {
f9e00a9f5870a9bcae2de8bf1cb3ce04703112e1Lennart Poettering /* This will load the service information files, but not actually
f9e00a9f5870a9bcae2de8bf1cb3ce04703112e1Lennart Poettering * start any services or anything */
f9e00a9f5870a9bcae2de8bf1cb3ce04703112e1Lennart Poettering if ((t = name_type_from_string(name)) == _NAME_TYPE_INVALID)
f9e00a9f5870a9bcae2de8bf1cb3ce04703112e1Lennart Poettering if ((r = set_put(ret->meta.names, n)) < 0) {
f9e00a9f5870a9bcae2de8bf1cb3ce04703112e1Lennart Poettering /* At this point the new entry is created and linked. However,
122676c9d9737f8591429fd5ffc9b454a994741dLennart Poettering * not loaded. Now load this entry and all its dependencies
122676c9d9737f8591429fd5ffc9b454a994741dLennart Poettering * recursively */
f9e00a9f5870a9bcae2de8bf1cb3ce04703112e1Lennart Poetteringvoid manager_dump_jobs(Manager *s, FILE *f, const char *prefix) {
f9e00a9f5870a9bcae2de8bf1cb3ce04703112e1Lennart Poetteringvoid manager_dump_names(Manager *s, FILE *f, const char *prefix) {
f9e00a9f5870a9bcae2de8bf1cb3ce04703112e1Lennart Poettering const char *t;