summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Fietkau2024-12-17 19:21:33 +0000
committerFelix Fietkau2024-12-17 19:47:49 +0000
commit32469644a029b79c1325c6f95e688d13988f76ad (patch)
tree0d4d3688817f0668516e1793f81796a75c7c0400
parent735b48728fca637970e20d998224dad09ac21cea (diff)
downloadprocd-32469644a029b79c1325c6f95e688d13988f76ad.tar.gz
service: allow incremental changes to service properties
Support updating data and autostart without re-running the init script or tearing down existing other service properties, e.g. validation or triggers. This can be used to allow services to manage their own data at runtime without going through the init script. Signed-off-by: Felix Fietkau <nbd@nbd.name>
-rw-r--r--service/service.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/service/service.c b/service/service.c
index de14aa3..25e2885 100644
--- a/service/service.c
+++ b/service/service.c
@@ -152,32 +152,28 @@ service_update_data(struct service *s, struct blob_attr *data)
}
static int
-service_update(struct service *s, struct blob_attr **tb, bool add)
+service_update(struct service *s, struct blob_attr **tb, bool add, bool init)
{
struct blob_attr *cur;
int rem;
- if (s->trigger) {
- trigger_del(s);
- free(s->trigger);
- s->trigger = NULL;
- }
-
- service_validate_del(s);
-
- if (tb[SERVICE_SET_AUTOSTART] && !blobmsg_get_bool(tb[SERVICE_SET_AUTOSTART]))
- s->autostart = false;
- else
+ if (tb[SERVICE_SET_AUTOSTART])
+ s->autostart = blobmsg_get_bool(tb[SERVICE_SET_AUTOSTART]);
+ else if (init)
s->autostart = true;
- if (tb[SERVICE_SET_TRIGGER] && blobmsg_data_len(tb[SERVICE_SET_TRIGGER])) {
+ if (tb[SERVICE_SET_TRIGGER]) {
+ free(s->trigger);
s->trigger = blob_memdup(tb[SERVICE_SET_TRIGGER]);
if (!s->trigger)
return -1;
+
+ trigger_del(s);
trigger_add(s->trigger, s);
}
- if (tb[SERVICE_SET_VALIDATE] && blobmsg_data_len(tb[SERVICE_SET_VALIDATE])) {
+ if (tb[SERVICE_SET_VALIDATE]) {
+ service_validate_del(s);
blobmsg_for_each_attr(cur, tb[SERVICE_SET_VALIDATE], rem)
service_validate_add(s, cur);
}
@@ -198,7 +194,8 @@ service_update(struct service *s, struct blob_attr **tb, bool add)
s->deleted = false;
- rc(s->name, "running");
+ if (init || tb[SERVICE_SET_INSTANCES])
+ rc(s->name, "running");
return 0;
}
@@ -441,7 +438,7 @@ service_handle_set(struct ubus_context *ctx, struct ubus_object *obj,
if (s) {
P_DEBUG(2, "Update service %s\n", name);
- return service_update(s, tb, add);
+ return service_update(s, tb, add, false);
}
P_DEBUG(2, "Create service %s\n", name);
@@ -451,7 +448,7 @@ service_handle_set(struct ubus_context *ctx, struct ubus_object *obj,
s->container = container;
- ret = service_update(s, tb, add);
+ ret = service_update(s, tb, add, true);
if (ret)
return ret;