From: Mike Yuan Date: Fri, 16 Jan 2026 19:53:47 +0000 (+0100) Subject: core/unit: several cleanups for unit_queue_job_check_and_collapse_type() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=12effc32da6dcdda32f27f9ffce636679d0a042a;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index 3c24645b47d..18a95955bc9 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -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).", diff --git a/src/core/unit.c b/src/core/unit.c index 5494d718e65..2cec0743f7a 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -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 diff --git a/src/core/unit.h b/src/core/unit.h index 57795cd5803..feaed9125ad 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -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 */ diff --git a/src/core/varlink-manager.c b/src/core/varlink-manager.c index 785cc206cce..8f09205ddd8 100644 --- a/src/core/varlink-manager.c +++ b/src/core/varlink-manager.c @@ -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);