From: Michael Vogt Date: Tue, 14 Apr 2026 14:24:07 +0000 (+0200) Subject: core: extract manager_setup_transient_unit() helper X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8edd9b2b66aacbf4d8bd061b76ba734fd39046b4;p=thirdparty%2Fsystemd.git core: extract manager_setup_transient_unit() helper Extract the transient unit setup logic from transient_unit_from_message() in dbus-manager.c into a shared helper. This prepares for reuse by the varlink StartTransient implementation. --- diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 1bc73e7b434..f48d04a4cb4 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -1028,7 +1028,6 @@ static int transient_unit_from_message( Unit **ret_unit, sd_bus_error *reterr_error) { - UnitType t; Unit *u; int r; @@ -1036,27 +1035,7 @@ static int transient_unit_from_message( assert(message); assert(name); - t = unit_name_to_type(name); - if (t < 0) - return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, - "Invalid unit name or type: %s", name); - - if (!unit_vtable[t]->can_transient) - return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, - "Unit type %s does not support transient units.", - unit_type_to_string(t)); - - r = manager_load_unit(m, name, NULL, reterr_error, &u); - if (r < 0) - return r; - - if (!unit_is_pristine(u)) - return sd_bus_error_setf(reterr_error, BUS_ERROR_UNIT_EXISTS, - "Unit %s was already loaded or has a fragment file.", name); - - /* OK, the unit failed to load and is unreferenced, now let's - * fill in the transient data instead */ - r = unit_make_transient(u); + r = manager_setup_transient_unit(m, name, &u, reterr_error); if (r < 0) return r; diff --git a/src/core/unit.c b/src/core/unit.c index 3404d7f8d3a..de0276a813a 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -4893,6 +4893,42 @@ int unit_make_transient(Unit *u) { return 0; } +int manager_setup_transient_unit(Manager *m, const char *name, Unit **ret, sd_bus_error *reterr_error) { + Unit *u; + int r; + + assert(m); + assert(name); + assert(ret); + + UnitType t = unit_name_to_type(name); + if (t < 0) + return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, + "Invalid unit name or type: %s", name); + + if (!unit_vtable[t]->can_transient) + return sd_bus_error_setf(reterr_error, SD_BUS_ERROR_INVALID_ARGS, + "Unit type %s does not support transient units.", + unit_type_to_string(t)); + + r = manager_load_unit(m, name, /* path= */ NULL, reterr_error, &u); + if (r < 0) + return r; + + if (!unit_is_pristine(u)) + return sd_bus_error_setf(reterr_error, BUS_ERROR_UNIT_EXISTS, + "Unit %s was already loaded or has a fragment file.", name); + + /* OK, the unit failed to load and is unreferenced, now let's + * fill in the transient data instead */ + r = unit_make_transient(u); + if (r < 0) + return r; + + *ret = u; + return 0; +} + static bool ignore_leftover_process(const char *comm) { return comm && comm[0] == '('; /* Most likely our own helper process (PAM?), ignore */ } diff --git a/src/core/unit.h b/src/core/unit.h index e503c2e344a..54794e8be7a 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -973,6 +973,7 @@ int unit_write_settingf(Unit *u, UnitWriteFlags flags, const char *name, const c int unit_kill_context(Unit *u, KillOperation k); int unit_make_transient(Unit *u); +int manager_setup_transient_unit(Manager *m, const char *name, Unit **ret, sd_bus_error *reterr_error); int unit_add_mounts_for(Unit *u, const char *path, UnitDependencyMask mask, UnitMountDependencyType type);