Unit **ret_unit,
sd_bus_error *reterr_error) {
- UnitType t;
Unit *u;
int r;
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;
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 */
}
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);