X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=src%2Fcore%2Ftransaction.c;h=2886a0598999c99aa19d31ea9db377c491867ea9;hb=a1230ff972a6a5d945749e5280cd092a2aa827dd;hp=710a6a394899a30cc6b0bc0dc4498b8d11ab5157;hpb=f19ca6105e9f74b01e799d02c280eec67696c228;p=thirdparty%2Fsystemd.git diff --git a/src/core/transaction.c b/src/core/transaction.c index 710a6a39489..2886a059899 100644 --- a/src/core/transaction.c +++ b/src/core/transaction.c @@ -1,20 +1,8 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ /*** This file is part of systemd. Copyright 2010 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see . ***/ #include @@ -345,8 +333,7 @@ static char* merge_unit_ids(const char* unit_log_field, char **pairs) { STRV_FOREACH_PAIR(unit_id, job_type, pairs) { next = strlen(unit_log_field) + strlen(*unit_id); if (!GREEDY_REALLOC(ans, alloc, size + next + 1)) { - free(ans); - return NULL; + return mfree(ans); } sprintf(ans + size, "%s%s", unit_log_field, *unit_id); @@ -361,6 +348,7 @@ 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; assert(tr); @@ -412,7 +400,7 @@ static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsi j->unit->id, unit_id == array ? "ordering cycle" : "dependency", *unit_id, *job_type, - unit_ids, NULL); + unit_ids); if (delete) { const char *status; @@ -421,7 +409,7 @@ static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsi "MESSAGE=%s: Job %s/%s deleted to break ordering cycle starting with %s/%s", j->unit->id, delete->unit->id, job_type_to_string(delete->type), j->unit->id, job_type_to_string(j->type), - unit_ids, NULL); + unit_ids); if (log_get_show_color()) status = ANSI_HIGHLIGHT_RED " SKIP " ANSI_NORMAL; @@ -437,7 +425,7 @@ static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsi log_struct(LOG_ERR, "MESSAGE=%s: Unable to break cycle starting with %s/%s", j->unit->id, j->unit->id, job_type_to_string(j->type), - unit_ids, NULL); + unit_ids); return sd_bus_error_setf(e, BUS_ERROR_TRANSACTION_ORDER_IS_CYCLIC, "Transaction order is cyclic. See system logs for details."); @@ -452,7 +440,7 @@ static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsi /* We assume that the dependencies are bidirectional, and * hence can ignore UNIT_AFTER */ - SET_FOREACH(u, j->unit->dependencies[UNIT_BEFORE], i) { + HASHMAP_FOREACH_KEY(v, u, j->unit->dependencies[UNIT_BEFORE], i) { Job *o; /* Is there a job for this unit? */ @@ -609,7 +597,7 @@ static int transaction_apply(Transaction *tr, Manager *m, JobMode mode) { /* Moves the transaction jobs to the set of active jobs */ - if (mode == JOB_ISOLATE || mode == JOB_FLUSH) { + if (IN_SET(mode, JOB_ISOLATE, JOB_FLUSH)) { /* When isolating first kill all installed jobs which * aren't part of the new transaction */ @@ -858,6 +846,31 @@ 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; + int r; + + assert(tr); + assert(unit); + + HASHMAP_FOREACH_KEY(v, dep, unit->dependencies[UNIT_PROPAGATES_RELOAD_TO], i) { + nt = job_type_collapse(JOB_TRY_RELOAD, dep); + if (nt == JOB_NOP) + continue; + + r = transaction_add_job_and_dependencies(tr, nt, dep, by, false, false, false, ignore_order, e); + if (r < 0) { + log_unit_warning(dep, + "Cannot add dependency reload job, ignoring: %s", + bus_error_message(e, r)); + sd_bus_error_free(e); + } + } +} + int transaction_add_job_and_dependencies( Transaction *tr, JobType type, @@ -868,11 +881,13 @@ int transaction_add_job_and_dependencies( bool ignore_requirements, bool ignore_order, sd_bus_error *e) { - Job *ret; + + bool is_new; Iterator i; Unit *dep; + Job *ret; + void *v; int r; - bool is_new; assert(tr); assert(type < _JOB_TYPE_MAX); @@ -905,7 +920,6 @@ int transaction_add_job_and_dependencies( "Job type %s is not applicable for unit %s.", job_type_to_string(type), unit->id); - /* First add the job. */ ret = transaction_add_one_job(tr, type, unit, &is_new); if (!ret) @@ -944,8 +958,8 @@ int transaction_add_job_and_dependencies( } /* Finally, recursively add in all dependencies. */ - if (type == JOB_START || type == JOB_RESTART) { - SET_FOREACH(dep, ret->unit->dependencies[UNIT_REQUIRES], i) { + if (IN_SET(type, JOB_START, JOB_RESTART)) { + HASHMAP_FOREACH_KEY(v, dep, ret->unit->dependencies[UNIT_REQUIRES], i) { 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 */ @@ -955,7 +969,7 @@ int transaction_add_job_and_dependencies( } } - SET_FOREACH(dep, ret->unit->dependencies[UNIT_BINDS_TO], i) { + HASHMAP_FOREACH_KEY(v, dep, ret->unit->dependencies[UNIT_BINDS_TO], i) { 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 */ @@ -965,7 +979,7 @@ int transaction_add_job_and_dependencies( } } - SET_FOREACH(dep, ret->unit->dependencies[UNIT_WANTS], i) { + HASHMAP_FOREACH_KEY(v, dep, ret->unit->dependencies[UNIT_WANTS], i) { 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. */ @@ -977,7 +991,7 @@ int transaction_add_job_and_dependencies( } } - SET_FOREACH(dep, ret->unit->dependencies[UNIT_REQUISITE], i) { + HASHMAP_FOREACH_KEY(v, dep, ret->unit->dependencies[UNIT_REQUISITE], i) { 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 */ @@ -987,7 +1001,7 @@ int transaction_add_job_and_dependencies( } } - SET_FOREACH(dep, ret->unit->dependencies[UNIT_CONFLICTS], i) { + HASHMAP_FOREACH_KEY(v, dep, ret->unit->dependencies[UNIT_CONFLICTS], i) { 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 */ @@ -997,7 +1011,7 @@ int transaction_add_job_and_dependencies( } } - SET_FOREACH(dep, ret->unit->dependencies[UNIT_CONFLICTED_BY], i) { + HASHMAP_FOREACH_KEY(v, dep, ret->unit->dependencies[UNIT_CONFLICTED_BY], i) { r = transaction_add_job_and_dependencies(tr, JOB_STOP, dep, ret, false, false, false, ignore_order, e); if (r < 0) { log_unit_warning(dep, @@ -1009,7 +1023,7 @@ int transaction_add_job_and_dependencies( } - if (type == JOB_STOP || type == JOB_RESTART) { + if (IN_SET(type, JOB_STOP, JOB_RESTART)) { static const UnitDependency propagate_deps[] = { UNIT_REQUIRED_BY, UNIT_REQUISITE_OF, @@ -1026,7 +1040,7 @@ int transaction_add_job_and_dependencies( ptype = type == JOB_RESTART ? JOB_TRY_RESTART : type; for (j = 0; j < ELEMENTSOF(propagate_deps); j++) - SET_FOREACH(dep, ret->unit->dependencies[propagate_deps[j]], i) { + HASHMAP_FOREACH_KEY(v, dep, ret->unit->dependencies[propagate_deps[j]], i) { JobType nt; nt = job_type_collapse(ptype, dep); @@ -1043,24 +1057,8 @@ int transaction_add_job_and_dependencies( } } - if (type == JOB_RELOAD) { - - SET_FOREACH(dep, ret->unit->dependencies[UNIT_PROPAGATES_RELOAD_TO], i) { - JobType nt; - - nt = job_type_collapse(JOB_TRY_RELOAD, dep); - if (nt == JOB_NOP) - continue; - - r = transaction_add_job_and_dependencies(tr, nt, dep, ret, false, false, false, ignore_order, e); - if (r < 0) { - log_unit_warning(dep, - "Cannot add dependency reload job, ignoring: %s", - bus_error_message(e, r)); - sd_bus_error_free(e); - } - } - } + if (type == JOB_RELOAD) + transaction_add_propagate_reload_jobs(tr, ret->unit, ret, ignore_order, e); /* JOB_VERIFY_STARTED require no dependency handling */ }