]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/unit: several cleanups for unit_queue_job_check_and_collapse_type() 40373/head
authorMike Yuan <me@yhndnzj.com>
Fri, 16 Jan 2026 19:53:47 +0000 (20:53 +0100)
committerMike Yuan <me@yhndnzj.com>
Sat, 17 Jan 2026 14:00:10 +0000 (15:00 +0100)
* Rename to _mangle_type() - it turned out this one doesn't collapse
  anything, but rather mangles the type if reload_if_possible is set.
  Hence name accordingly.
* Use -ELIBEXEC rather than -EUNATCH to denote dependency only units.
* Add a comment about the JOB_STOP and load state check.

src/core/dbus-unit.c
src/core/unit.c
src/core/unit.h
src/core/varlink-manager.c

index 3c24645b47d0660bc0aebd0f0ca7afafb1690a17..18a95955bc9c1bc60ee0cd1b49d22e9053cb825c 100644 (file)
@@ -1962,10 +1962,10 @@ int bus_unit_queue_job_one(
 
         assert(u);
 
-        r = unit_queue_job_check_and_collapse_type(u, &type, /* reload_if_possible= */ FLAGS_SET(flags, BUS_UNIT_QUEUE_RELOAD_IF_POSSIBLE));
+        r = unit_queue_job_check_and_mangle_type(u, &type, /* reload_if_possible= */ FLAGS_SET(flags, BUS_UNIT_QUEUE_RELOAD_IF_POSSIBLE));
         if (r == -ENOENT)
                 return sd_bus_error_setf(reterr_error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s not loaded.", u->id);
-        if (r == -EUNATCH)
+        if (r == -ELIBEXEC)
                 return sd_bus_error_setf(reterr_error,
                                          BUS_ERROR_ONLY_BY_DEPENDENCY,
                                          "Operation refused, unit %s may be requested by dependency only (it is configured to refuse manual start/stop).",
index 5494d718e65b6d6e8c06d1aa9d7bb96a5ac00acc..2cec0743f7ae6620bcb6261abd3b3379d6a67368 100644 (file)
@@ -7004,7 +7004,7 @@ UnitDependency unit_mount_dependency_type_to_dependency_type(UnitMountDependency
         }
 }
 
-int unit_queue_job_check_and_collapse_type(
+int unit_queue_job_check_and_mangle_type(
                 Unit *u,
                 JobType *type, /* input and output */
                 bool reload_if_possible) {
@@ -7012,7 +7012,7 @@ int unit_queue_job_check_and_collapse_type(
         /* Returns:
          *
          * -ENOENT    → Unit not loaded
-         * -EUNATCH   → Unit can only be activated via dependency, not directly
+         * -ELIBEXEC  → Unit can only be activated via dependency, not directly
          * -ESHUTDOWN → System bus is shutting down */
 
         JobType t;
@@ -7029,6 +7029,8 @@ int unit_queue_job_check_and_collapse_type(
                         t = JOB_TRY_RELOAD;
         }
 
+        /* Our transaction logic allows units not properly loaded to be stopped. But if already dead
+         * let's return clear error to caller. */
         if (t == JOB_STOP && UNIT_IS_LOAD_ERROR(u->load_state) && unit_active_state(u) == UNIT_INACTIVE)
                 return -ENOENT;
 
@@ -7036,7 +7038,7 @@ int unit_queue_job_check_and_collapse_type(
             (t == JOB_STOP && u->refuse_manual_stop) ||
             (IN_SET(t, JOB_RESTART, JOB_TRY_RESTART) && (u->refuse_manual_start || u->refuse_manual_stop)) ||
             (t == JOB_RELOAD_OR_START && job_type_collapse(t, u) == JOB_START && u->refuse_manual_start))
-                return -EUNATCH;
+                return -ELIBEXEC;
 
         /* dbus-broker issues StartUnit for activation requests, and Type=dbus services automatically
          * gain dependency on dbus.socket. Therefore, if dbus has a pending stop job, the new start
index 57795cd580381811de7c08c3144a5afbb65d1fa1..feaed9125adf3b19a2204f6775a8219f6dbcf219 100644 (file)
@@ -1092,7 +1092,7 @@ UnitDependency unit_mount_dependency_type_to_dependency_type(UnitMountDependency
 
 DECLARE_STRING_TABLE_LOOKUP(oom_policy, OOMPolicy);
 
-int unit_queue_job_check_and_collapse_type(Unit *u, JobType *type, bool reload_if_possible);
+int unit_queue_job_check_and_mangle_type(Unit *u, JobType *type, bool reload_if_possible);
 
 /* Macros which append UNIT= or USER_UNIT= to the message */
 
index 785cc206ccee7d4880bf1df637ca44e1256273bc..8f09205ddd8ebe594e7250c6dd73672410e56883 100644 (file)
@@ -315,10 +315,10 @@ static int varlink_manager_queue_job_one(
 
         assert(u);
 
-        r = unit_queue_job_check_and_collapse_type(u, &type, /* reload_if_possible= */ BIT_SET(u->markers, UNIT_MARKER_NEEDS_RELOAD));
+        r = unit_queue_job_check_and_mangle_type(u, &type, /* reload_if_possible= */ BIT_SET(u->markers, UNIT_MARKER_NEEDS_RELOAD));
         if (r == -ENOENT)
                 return varlink_error_no_such_unit(link, "name");
-        if (r == -EUNATCH)
+        if (r == -ELIBEXEC)
                 return sd_varlink_errorb(link, VARLINK_ERROR_MANAGER_ONLY_BY_DEPENDENCY);
         if (r == -ESHUTDOWN)
                 return sd_varlink_errorb(link, VARLINK_ERROR_MANAGER_BUS_SHUTTING_DOWN);