From 90e74a66e663f1776457d599cb7d5ce44785a56c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 8 Sep 2020 11:58:29 +0200 Subject: tree-wide: define iterator inside of the macro --- src/core/transaction.c | 59 ++++++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 36 deletions(-) (limited to 'src/core/transaction.c') diff --git a/src/core/transaction.c b/src/core/transaction.c index 0fa419787e..ab07c80f1d 100644 --- a/src/core/transaction.c +++ b/src/core/transaction.c @@ -218,14 +218,13 @@ static int delete_one_unmergeable_job(Transaction *tr, Job *j) { static int transaction_merge_jobs(Transaction *tr, sd_bus_error *e) { Job *j; - Iterator i; int r; assert(tr); /* First step, check whether any of the jobs for one specific * task conflict. If so, try to drop one of them. */ - HASHMAP_FOREACH(j, tr->jobs, i) { + HASHMAP_FOREACH(j, tr->jobs) { JobType t; Job *k; @@ -256,7 +255,7 @@ static int transaction_merge_jobs(Transaction *tr, sd_bus_error *e) { } /* Second step, merge the jobs. */ - HASHMAP_FOREACH(j, tr->jobs, i) { + HASHMAP_FOREACH(j, tr->jobs) { JobType t = j->type; Job *k; @@ -288,12 +287,11 @@ static void transaction_drop_redundant(Transaction *tr) { assert(tr); do { - Iterator i; Job *j; again = false; - HASHMAP_FOREACH(j, tr->jobs, i) { + HASHMAP_FOREACH(j, tr->jobs) { bool keep = false; Job *k; @@ -349,7 +347,6 @@ static char* merge_unit_ids(const char* unit_log_field, char **pairs) { } static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsigned generation, sd_bus_error *e) { - Iterator i; Unit *u; void *v; int r; @@ -453,7 +450,7 @@ static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsi * ordering dependencies and we test with job_compare() whether it is the 'before' edge in the job * execution ordering. */ for (d = 0; d < ELEMENTSOF(directions); d++) { - HASHMAP_FOREACH_KEY(v, u, j->unit->dependencies[directions[d]], i) { + HASHMAP_FOREACH_KEY(v, u, j->unit->dependencies[directions[d]]) { Job *o; /* Is there a job for this unit? */ @@ -487,7 +484,6 @@ static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsi static int transaction_verify_order(Transaction *tr, unsigned *generation, sd_bus_error *e) { Job *j; int r; - Iterator i; unsigned g; assert(tr); @@ -498,7 +494,7 @@ static int transaction_verify_order(Transaction *tr, unsigned *generation, sd_bu g = (*generation)++; - HASHMAP_FOREACH(j, tr->jobs, i) { + HASHMAP_FOREACH(j, tr->jobs) { r = transaction_verify_order_one(tr, j, NULL, g, e); if (r < 0) return r; @@ -515,12 +511,11 @@ static void transaction_collect_garbage(Transaction *tr) { /* Drop jobs that are not required by any other job */ do { - Iterator i; Job *j; again = false; - HASHMAP_FOREACH(j, tr->jobs, i) { + HASHMAP_FOREACH(j, tr->jobs) { if (tr->anchor_job == j) continue; @@ -541,7 +536,6 @@ static void transaction_collect_garbage(Transaction *tr) { } static int transaction_is_destructive(Transaction *tr, JobMode mode, sd_bus_error *e) { - Iterator i; Job *j; assert(tr); @@ -549,7 +543,7 @@ static int transaction_is_destructive(Transaction *tr, JobMode mode, sd_bus_erro /* Checks whether applying this transaction means that * existing jobs would be replaced */ - HASHMAP_FOREACH(j, tr->jobs, i) { + HASHMAP_FOREACH(j, tr->jobs) { /* Assume merged */ assert(!j->transaction_prev); @@ -568,7 +562,6 @@ static int transaction_is_destructive(Transaction *tr, JobMode mode, sd_bus_erro static void transaction_minimize_impact(Transaction *tr) { Job *j; - Iterator i; assert(tr); @@ -576,7 +569,7 @@ static void transaction_minimize_impact(Transaction *tr) { * or that stop a running service. */ rescan: - HASHMAP_FOREACH(j, tr->jobs, i) { + HASHMAP_FOREACH(j, tr->jobs) { LIST_FOREACH(transaction, j, j) { bool stops_running_service, changes_existing_job; @@ -625,7 +618,6 @@ static int transaction_apply( JobMode mode, Set *affected_jobs) { - Iterator i; Job *j; int r; @@ -635,7 +627,7 @@ static int transaction_apply( /* When isolating first kill all installed jobs which * aren't part of the new transaction */ - HASHMAP_FOREACH(j, m->jobs, i) { + HASHMAP_FOREACH(j, m->jobs) { assert(j->installed); if (j->unit->ignore_on_isolate) @@ -651,7 +643,7 @@ static int transaction_apply( } } - HASHMAP_FOREACH(j, tr->jobs, i) { + HASHMAP_FOREACH(j, tr->jobs) { /* Assume merged */ assert(!j->transaction_prev); assert(!j->transaction_next); @@ -696,7 +688,7 @@ static int transaction_apply( rollback: - HASHMAP_FOREACH(j, tr->jobs, i) + HASHMAP_FOREACH(j, tr->jobs) hashmap_remove(m->jobs, UINT32_TO_PTR(j->id)); return r; @@ -709,7 +701,6 @@ int transaction_activate( Set *affected_jobs, sd_bus_error *e) { - Iterator i; Job *j; int r; unsigned generation = 1; @@ -722,7 +713,7 @@ int transaction_activate( /* Reset the generation counter of all installed jobs. The detection of cycles * looks at installed jobs. If they had a non-zero generation from some previous * walk of the graph, the algorithm would break. */ - HASHMAP_FOREACH(j, m->jobs, i) + HASHMAP_FOREACH(j, m->jobs) j->generation = 0; /* First step: figure out which jobs matter */ @@ -890,7 +881,6 @@ static void transaction_unlink_job(Transaction *tr, Job *j, bool delete_dependen } void transaction_add_propagate_reload_jobs(Transaction *tr, Unit *unit, Job *by, bool ignore_order, sd_bus_error *e) { - Iterator i; JobType nt; Unit *dep; void *v; @@ -899,7 +889,7 @@ void transaction_add_propagate_reload_jobs(Transaction *tr, Unit *unit, Job *by, assert(tr); assert(unit); - HASHMAP_FOREACH_KEY(v, dep, unit->dependencies[UNIT_PROPAGATES_RELOAD_TO], i) { + HASHMAP_FOREACH_KEY(v, dep, unit->dependencies[UNIT_PROPAGATES_RELOAD_TO]) { nt = job_type_collapse(JOB_TRY_RELOAD, dep); if (nt == JOB_NOP) continue; @@ -926,7 +916,6 @@ int transaction_add_job_and_dependencies( sd_bus_error *e) { bool is_new; - Iterator i; Unit *dep; Job *ret; void *v; @@ -1006,7 +995,7 @@ int transaction_add_job_and_dependencies( /* If we are following some other unit, make sure we * add all dependencies of everybody following. */ if (unit_following_set(ret->unit, &following) > 0) { - SET_FOREACH(dep, following, i) { + SET_FOREACH(dep, following) { r = transaction_add_job_and_dependencies(tr, type, dep, ret, false, false, false, ignore_order, e); if (r < 0) { log_unit_full(dep, @@ -1022,7 +1011,7 @@ int transaction_add_job_and_dependencies( /* Finally, recursively add in all dependencies. */ if (IN_SET(type, JOB_START, JOB_RESTART)) { - HASHMAP_FOREACH_KEY(v, dep, ret->unit->dependencies[UNIT_REQUIRES], i) { + HASHMAP_FOREACH_KEY(v, dep, ret->unit->dependencies[UNIT_REQUIRES]) { r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, true, false, false, ignore_order, e); if (r < 0) { if (r != -EBADR) /* job type not applicable */ @@ -1032,7 +1021,7 @@ int transaction_add_job_and_dependencies( } } - HASHMAP_FOREACH_KEY(v, dep, ret->unit->dependencies[UNIT_BINDS_TO], i) { + HASHMAP_FOREACH_KEY(v, dep, ret->unit->dependencies[UNIT_BINDS_TO]) { r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, true, false, false, ignore_order, e); if (r < 0) { if (r != -EBADR) /* job type not applicable */ @@ -1042,7 +1031,7 @@ int transaction_add_job_and_dependencies( } } - HASHMAP_FOREACH_KEY(v, dep, ret->unit->dependencies[UNIT_WANTS], i) { + HASHMAP_FOREACH_KEY(v, dep, ret->unit->dependencies[UNIT_WANTS]) { r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, false, false, false, ignore_order, e); if (r < 0) { /* unit masked, job type not applicable and unit not found are not considered as errors. */ @@ -1054,7 +1043,7 @@ int transaction_add_job_and_dependencies( } } - HASHMAP_FOREACH_KEY(v, dep, ret->unit->dependencies[UNIT_REQUISITE], i) { + HASHMAP_FOREACH_KEY(v, dep, ret->unit->dependencies[UNIT_REQUISITE]) { r = transaction_add_job_and_dependencies(tr, JOB_VERIFY_ACTIVE, dep, ret, true, false, false, ignore_order, e); if (r < 0) { if (r != -EBADR) /* job type not applicable */ @@ -1064,7 +1053,7 @@ int transaction_add_job_and_dependencies( } } - HASHMAP_FOREACH_KEY(v, dep, ret->unit->dependencies[UNIT_CONFLICTS], i) { + HASHMAP_FOREACH_KEY(v, dep, ret->unit->dependencies[UNIT_CONFLICTS]) { r = transaction_add_job_and_dependencies(tr, JOB_STOP, dep, ret, true, true, false, ignore_order, e); if (r < 0) { if (r != -EBADR) /* job type not applicable */ @@ -1074,7 +1063,7 @@ int transaction_add_job_and_dependencies( } } - HASHMAP_FOREACH_KEY(v, dep, ret->unit->dependencies[UNIT_CONFLICTED_BY], i) { + HASHMAP_FOREACH_KEY(v, dep, ret->unit->dependencies[UNIT_CONFLICTED_BY]) { r = transaction_add_job_and_dependencies(tr, JOB_STOP, dep, ret, false, false, false, ignore_order, e); if (r < 0) { log_unit_warning(dep, @@ -1103,7 +1092,7 @@ int transaction_add_job_and_dependencies( ptype = type == JOB_RESTART ? JOB_TRY_RESTART : type; for (j = 0; j < ELEMENTSOF(propagate_deps); j++) - HASHMAP_FOREACH_KEY(v, dep, ret->unit->dependencies[propagate_deps[j]], i) { + HASHMAP_FOREACH_KEY(v, dep, ret->unit->dependencies[propagate_deps[j]]) { JobType nt; nt = job_type_collapse(ptype, dep); @@ -1133,7 +1122,6 @@ fail: } int transaction_add_isolate_jobs(Transaction *tr, Manager *m) { - Iterator i; Unit *u; char *k; int r; @@ -1141,7 +1129,7 @@ int transaction_add_isolate_jobs(Transaction *tr, Manager *m) { assert(tr); assert(m); - HASHMAP_FOREACH_KEY(u, k, m->units, i) { + HASHMAP_FOREACH_KEY(u, k, m->units) { /* ignore aliases */ if (u->id != k) @@ -1167,7 +1155,6 @@ int transaction_add_isolate_jobs(Transaction *tr, Manager *m) { } int transaction_add_triggering_jobs(Transaction *tr, Unit *u) { - Iterator i; void *v; Unit *trigger; int r; @@ -1175,7 +1162,7 @@ int transaction_add_triggering_jobs(Transaction *tr, Unit *u) { assert(tr); assert(u); - HASHMAP_FOREACH_KEY(v, trigger, u->dependencies[UNIT_TRIGGERED_BY], i) { + HASHMAP_FOREACH_KEY(v, trigger, u->dependencies[UNIT_TRIGGERED_BY]) { /* No need to stop inactive jobs */ if (UNIT_IS_INACTIVE_OR_FAILED(unit_active_state(trigger)) && !trigger->job) continue; -- cgit v1.2.1