core/unit: several cleanups for unit_queue_job_check_and_collapse_type()

* 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.
This commit is contained in:
Mike Yuan
2026-01-17 15:00:10 +01:00
parent 490067d41c
commit 12effc32da
4 changed files with 10 additions and 8 deletions
+2 -2
View 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).",
+5 -3
View 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
+1 -1
View 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 */
+2 -2
View 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);