summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Golle2021-09-15 20:29:23 +0000
committerDaniel Golle2021-09-15 20:43:23 +0000
commit68df9ac60426e1bb229c2c1a1127082f587dd432 (patch)
treefd19dc9615fceb8bf3df4a35f1c66edccbd0f82a
parent8a60e7e066cb0b364cae13c524dce16743633b0a (diff)
downloadprocd-68df9ac60426e1bb229c2c1a1127082f587dd432.tar.gz
procd: fix container deletion
Deleting a container could lead to an attempt NULL-pointer dereference crashing procd and triggering a reboot of the system. Properly handle service deletion to avoid that. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
-rw-r--r--service/service.c13
-rw-r--r--service/service.h1
2 files changed, 5 insertions, 9 deletions
diff --git a/service/service.c b/service/service.c
index 419f96c..48825c3 100644
--- a/service/service.c
+++ b/service/service.c
@@ -182,8 +182,6 @@ service_update(struct service *s, struct blob_attr **tb, bool add)
return 0;
}
-static void _service_stopped(struct service *s, bool container);
-
static void
service_delete(struct service *s, bool container)
{
@@ -191,7 +189,7 @@ service_delete(struct service *s, bool container)
free(s->data);
vlist_flush_all(&s->instances);
s->deleted = true;
- _service_stopped(s, container);
+ service_stopped(s);
}
enum {
@@ -430,6 +428,8 @@ service_handle_set(struct ubus_context *ctx, struct ubus_object *obj,
if (!s)
return UBUS_STATUS_UNKNOWN_ERROR;
+ s->container = container;
+
ret = service_update(s, tb, add);
if (ret)
return ret;
@@ -1009,13 +1009,8 @@ service_start_early(char *name, char *cmdline, char *user, char *group)
void service_stopped(struct service *s)
{
- _service_stopped(s, false);
-}
-
-static void _service_stopped(struct service *s, bool container)
-{
if (s->deleted && avl_is_empty(&s->instances.avl)) {
- if (container) {
+ if (s->container) {
service_event("container.stop", s->name, NULL);
avl_delete(&containers, &s->avl);
} else {
diff --git a/service/service.h b/service/service.h
index 48157cc..e148369 100644
--- a/service/service.h
+++ b/service/service.h
@@ -44,6 +44,7 @@ struct service {
const char *name;
bool deleted;
bool autostart;
+ bool container;
struct blob_attr *trigger;
struct vlist_tree instances;