transaction: turn four bool parameters into a proper flags parameters

This commit is contained in:
Lennart Poettering
2023-06-20 13:02:09 +02:00
parent 68f8a86a46
commit b0904249b9
3 changed files with 55 additions and 30 deletions
+16 -5
View File
@@ -2052,9 +2052,15 @@ int manager_add_job(
if (!tr)
return -ENOMEM;
r = transaction_add_job_and_dependencies(tr, type, unit, NULL, true, false,
IN_SET(mode, JOB_IGNORE_DEPENDENCIES, JOB_IGNORE_REQUIREMENTS),
mode == JOB_IGNORE_DEPENDENCIES, error);
r = transaction_add_job_and_dependencies(
tr,
type,
unit,
/* by= */ NULL,
TRANSACTION_MATTERS |
(IN_SET(mode, JOB_IGNORE_DEPENDENCIES, JOB_IGNORE_REQUIREMENTS) ? TRANSACTION_IGNORE_REQUIREMENTS : 0) |
(mode == JOB_IGNORE_DEPENDENCIES ? TRANSACTION_IGNORE_ORDER : 0),
error);
if (r < 0)
return r;
@@ -2132,12 +2138,17 @@ int manager_propagate_reload(Manager *m, Unit *unit, JobMode mode, sd_bus_error
return -ENOMEM;
/* We need an anchor job */
r = transaction_add_job_and_dependencies(tr, JOB_NOP, unit, NULL, false, false, true, true, e);
r = transaction_add_job_and_dependencies(tr, JOB_NOP, unit, NULL, TRANSACTION_IGNORE_REQUIREMENTS|TRANSACTION_IGNORE_ORDER, e);
if (r < 0)
return r;
/* Failure in adding individual dependencies is ignored, so this always succeeds. */
transaction_add_propagate_reload_jobs(tr, unit, tr->anchor_job, mode == JOB_IGNORE_DEPENDENCIES, e);
transaction_add_propagate_reload_jobs(
tr,
unit,
tr->anchor_job,
mode == JOB_IGNORE_DEPENDENCIES ? TRANSACTION_IGNORE_ORDER : 0,
e);
r = transaction_activate(tr, m, mode, NULL, e);
if (r < 0)
+24 -20
View File
@@ -874,7 +874,13 @@ 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) {
void transaction_add_propagate_reload_jobs(
Transaction *tr,
Unit *unit,
Job *by,
TransactionAddFlags flags,
sd_bus_error *e) {
JobType nt;
Unit *dep;
int r;
@@ -887,7 +893,7 @@ void transaction_add_propagate_reload_jobs(Transaction *tr, Unit *unit, Job *by,
if (nt == JOB_NOP)
continue;
r = transaction_add_job_and_dependencies(tr, nt, dep, by, false, false, false, ignore_order, e);
r = transaction_add_job_and_dependencies(tr, nt, dep, by, flags, e);
if (r < 0) {
log_unit_warning(dep,
"Cannot add dependency reload job, ignoring: %s",
@@ -902,10 +908,7 @@ int transaction_add_job_and_dependencies(
JobType type,
Unit *unit,
Job *by,
bool matters,
bool conflicts,
bool ignore_requirements,
bool ignore_order,
TransactionAddFlags flags,
sd_bus_error *e) {
bool is_new;
@@ -969,11 +972,12 @@ int transaction_add_job_and_dependencies(
if (!ret)
return -ENOMEM;
ret->ignore_order = ret->ignore_order || ignore_order;
if (FLAGS_SET(flags, TRANSACTION_IGNORE_ORDER))
ret->ignore_order = true;
/* Then, add a link to the job. */
if (by) {
if (!job_dependency_new(by, ret, matters, conflicts))
if (!job_dependency_new(by, ret, FLAGS_SET(flags, TRANSACTION_MATTERS), FLAGS_SET(flags, TRANSACTION_CONFLICTS)))
return -ENOMEM;
} else {
/* If the job has no parent job, it is the anchor job. */
@@ -981,14 +985,14 @@ int transaction_add_job_and_dependencies(
tr->anchor_job = ret;
}
if (is_new && !ignore_requirements && type != JOB_NOP) {
if (is_new && !FLAGS_SET(flags, TRANSACTION_IGNORE_REQUIREMENTS) && type != JOB_NOP) {
_cleanup_set_free_ Set *following = NULL;
/* 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) {
r = transaction_add_job_and_dependencies(tr, type, dep, ret, false, false, false, ignore_order, e);
r = transaction_add_job_and_dependencies(tr, type, dep, ret, flags & TRANSACTION_IGNORE_ORDER, e);
if (r < 0) {
log_unit_full_errno(dep, r == -ERFKILL ? LOG_INFO : LOG_WARNING, r,
"Cannot add dependency job, ignoring: %s",
@@ -1000,7 +1004,7 @@ int transaction_add_job_and_dependencies(
/* Finally, recursively add in all dependencies. */
if (IN_SET(type, JOB_START, JOB_RESTART)) {
UNIT_FOREACH_DEPENDENCY(dep, ret->unit, UNIT_ATOM_PULL_IN_START) {
r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, true, false, false, ignore_order, e);
r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, TRANSACTION_MATTERS | (flags & TRANSACTION_IGNORE_ORDER), e);
if (r < 0) {
if (r != -EBADR) /* job type not applicable */
goto fail;
@@ -1010,7 +1014,7 @@ int transaction_add_job_and_dependencies(
}
UNIT_FOREACH_DEPENDENCY(dep, ret->unit, UNIT_ATOM_PULL_IN_START_IGNORED) {
r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, false, false, false, ignore_order, e);
r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, flags & TRANSACTION_IGNORE_ORDER, e);
if (r < 0) {
/* unit masked, job type not applicable and unit not found are not considered as errors. */
log_unit_full_errno(dep,
@@ -1022,7 +1026,7 @@ int transaction_add_job_and_dependencies(
}
UNIT_FOREACH_DEPENDENCY(dep, ret->unit, UNIT_ATOM_PULL_IN_VERIFY) {
r = transaction_add_job_and_dependencies(tr, JOB_VERIFY_ACTIVE, dep, ret, true, false, false, ignore_order, e);
r = transaction_add_job_and_dependencies(tr, JOB_VERIFY_ACTIVE, dep, ret, TRANSACTION_MATTERS | (flags & TRANSACTION_IGNORE_ORDER), e);
if (r < 0) {
if (r != -EBADR) /* job type not applicable */
goto fail;
@@ -1032,7 +1036,7 @@ int transaction_add_job_and_dependencies(
}
UNIT_FOREACH_DEPENDENCY(dep, ret->unit, UNIT_ATOM_PULL_IN_STOP) {
r = transaction_add_job_and_dependencies(tr, JOB_STOP, dep, ret, true, true, false, ignore_order, e);
r = transaction_add_job_and_dependencies(tr, JOB_STOP, dep, ret, TRANSACTION_MATTERS | TRANSACTION_CONFLICTS | (flags & TRANSACTION_IGNORE_ORDER), e);
if (r < 0) {
if (r != -EBADR) /* job type not applicable */
goto fail;
@@ -1042,7 +1046,7 @@ int transaction_add_job_and_dependencies(
}
UNIT_FOREACH_DEPENDENCY(dep, ret->unit, UNIT_ATOM_PULL_IN_STOP_IGNORED) {
r = transaction_add_job_and_dependencies(tr, JOB_STOP, dep, ret, false, false, false, ignore_order, e);
r = transaction_add_job_and_dependencies(tr, JOB_STOP, dep, ret, flags & TRANSACTION_IGNORE_ORDER, e);
if (r < 0) {
log_unit_warning(dep,
"Cannot add dependency job, ignoring: %s",
@@ -1069,7 +1073,7 @@ int transaction_add_job_and_dependencies(
if (nt == JOB_NOP)
continue;
r = transaction_add_job_and_dependencies(tr, nt, dep, ret, true, false, false, ignore_order, e);
r = transaction_add_job_and_dependencies(tr, nt, dep, ret, TRANSACTION_MATTERS | (flags & TRANSACTION_IGNORE_ORDER), e);
if (r < 0) {
if (r != -EBADR) /* job type not applicable */
return r;
@@ -1085,7 +1089,7 @@ int transaction_add_job_and_dependencies(
if (set_contains(propagated_restart, dep))
continue;
r = transaction_add_job_and_dependencies(tr, JOB_STOP, dep, ret, true, false, false, ignore_order, e);
r = transaction_add_job_and_dependencies(tr, JOB_STOP, dep, ret, TRANSACTION_MATTERS | (flags & TRANSACTION_IGNORE_ORDER), e);
if (r < 0) {
if (r != -EBADR) /* job type not applicable */
return r;
@@ -1096,7 +1100,7 @@ int transaction_add_job_and_dependencies(
}
if (type == JOB_RELOAD)
transaction_add_propagate_reload_jobs(tr, ret->unit, ret, ignore_order, e);
transaction_add_propagate_reload_jobs(tr, ret->unit, ret, flags & TRANSACTION_IGNORE_ORDER, e);
/* JOB_VERIFY_ACTIVE requires no dependency handling */
}
@@ -1157,7 +1161,7 @@ int transaction_add_isolate_jobs(Transaction *tr, Manager *m) {
if (keep)
continue;
r = transaction_add_job_and_dependencies(tr, JOB_STOP, u, tr->anchor_job, true, false, false, false, NULL);
r = transaction_add_job_and_dependencies(tr, JOB_STOP, u, tr->anchor_job, TRANSACTION_MATTERS, NULL);
if (r < 0)
log_unit_warning_errno(u, r, "Cannot add isolate job, ignoring: %m");
}
@@ -1182,7 +1186,7 @@ int transaction_add_triggering_jobs(Transaction *tr, Unit *u) {
if (hashmap_contains(tr->jobs, trigger))
continue;
r = transaction_add_job_and_dependencies(tr, JOB_STOP, trigger, tr->anchor_job, true, false, false, false, NULL);
r = transaction_add_job_and_dependencies(tr, JOB_STOP, trigger, tr->anchor_job, TRANSACTION_MATTERS, NULL);
if (r < 0)
log_unit_warning_errno(u, r, "Cannot add triggered by job, ignoring: %m");
}
+15 -5
View File
@@ -20,17 +20,27 @@ Transaction *transaction_free(Transaction *tr);
Transaction *transaction_abort_and_free(Transaction *tr);
DEFINE_TRIVIAL_CLEANUP_FUNC(Transaction*, transaction_abort_and_free);
void transaction_add_propagate_reload_jobs(Transaction *tr, Unit *unit, Job *by, bool ignore_order, sd_bus_error *e);
typedef enum TransactionAddFlags {
TRANSACTION_MATTERS = 1 << 0,
TRANSACTION_CONFLICTS = 1 << 1,
TRANSACTION_IGNORE_REQUIREMENTS = 1 << 2,
TRANSACTION_IGNORE_ORDER = 1 << 3,
} TransactionAddFlags;
void transaction_add_propagate_reload_jobs(
Transaction *tr,
Unit *unit, Job *by,
TransactionAddFlags flags,
sd_bus_error *e);
int transaction_add_job_and_dependencies(
Transaction *tr,
JobType type,
Unit *unit,
Job *by,
bool matters,
bool conflicts,
bool ignore_requirements,
bool ignore_order,
TransactionAddFlags flags,
sd_bus_error *e);
int transaction_activate(Transaction *tr, Manager *m, JobMode mode, Set *affected, sd_bus_error *e);
int transaction_add_isolate_jobs(Transaction *tr, Manager *m);
int transaction_add_triggering_jobs(Transaction *tr, Unit *u);