]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
transaction: turn four bool parameters into a proper flags parameters
authorLennart Poettering <lennart@poettering.net>
Tue, 20 Jun 2023 10:19:03 +0000 (12:19 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 20 Jun 2023 11:02:09 +0000 (13:02 +0200)
src/core/manager.c
src/core/transaction.c
src/core/transaction.h

index 1df48d3cbc968d33dea1ff2e25c0d9b1d9542026..34a6d7db2cd64e0008f6e764cd70170ecf21bf31 100644 (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)
index 39f8f6c96df7b7ab3dc5bc527d99ccc219750a61..bb38741ec31d05614d5ae612569ff8bd904c552f 100644 (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");
         }
index b42d434dd1446b7362ee3c9b53e9e5d8d38d97b7..6ee0872c2738fb5bed04689a698cf3085d90622c 100644 (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);