static JSON_DISPATCH_ENUM_DEFINE(dispatch_job_mode, JobMode, job_mode_from_string);
typedef struct TransientServiceParameters {
+ bool present;
ServiceType type;
TransientExecCommandItem *exec_start;
size_t n_exec_start;
};
StartTransientContextParameters *p = ASSERT_PTR(userdata);
+ p->service.present = true;
return sd_json_dispatch(variant, service_dispatch, /* flags= */ 0, &p->service);
}
return r;
}
-static int transient_service_apply_properties(Unit *u, TransientServiceParameters *sp) {
+static int transient_unit_apply_properties(Unit *u, StartTransientContextParameters *p) {
+ int r;
+
+ assert(u);
+ assert(p);
+
+ if (p->description) {
+ r = unit_set_description(u, p->description);
+ if (r < 0)
+ return r;
+ unit_write_settingf(u, UNIT_RUNTIME|UNIT_ESCAPE_SPECIFIERS, "Description", "Description=%s", p->description);
+ }
+
+ return 0;
+}
+
+static int transient_service_apply_properties(Service *s, TransientServiceParameters *sp) {
+ Unit *u = UNIT(ASSERT_PTR(s));
int r;
- Service *s = ASSERT_PTR(SERVICE(u));
assert(sp);
if (sp->type >= 0) {
return varlink_reply_bus_error(link, r, &bus_error);
/* Apply unit-level properties from context */
- if (p.context.description) {
- r = unit_set_description(u, p.context.description);
- if (r < 0)
- return sd_varlink_error(link, VARLINK_ERROR_UNIT_BAD_SETTING, NULL);
- unit_write_settingf(u, UNIT_RUNTIME|UNIT_ESCAPE_SPECIFIERS, "Description", "Description=%s", p.context.description);
- }
+ r = transient_unit_apply_properties(u, &p.context);
+ if (r < 0)
+ return sd_varlink_error(link, VARLINK_ERROR_UNIT_BAD_SETTING, NULL);
/* Apply service-specific properties from context.Service */
- if (p.context.service.type >= 0 || p.context.service.n_exec_start > 0 || p.context.service.remain_after_exit >= 0) {
- if (t != UNIT_SERVICE)
- return sd_varlink_error(link, VARLINK_ERROR_UNIT_TYPE_NOT_SUPPORTED, NULL);
-
- r = transient_service_apply_properties(u, &p.context.service);
+ Service *s = SERVICE(u);
+ if (s) {
+ r = transient_service_apply_properties(s, &p.context.service);
if (r < 0)
return sd_varlink_error(link, VARLINK_ERROR_UNIT_BAD_SETTING, NULL);
- }
+ } else if (p.context.service.present)
+ return sd_varlink_error(link, VARLINK_ERROR_UNIT_TYPE_NOT_SUPPORTED, NULL);
unit_add_to_load_queue(u);
manager_dispatch_load_queue(manager);