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.
This commit is contained in:
+1
-22
@@ -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;
|
||||
|
||||
|
||||
@@ -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 */
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user