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:
@@ -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 */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user