From: Daniel Golle Date: Wed, 15 Sep 2021 20:29:23 +0000 (+0100) Subject: procd: fix container deletion X-Git-Url: http://git.openwrt.org/ubox.git?a=commitdiff_plain;h=68df9ac60426e1bb229c2c1a1127082f587dd432;p=project%2Fprocd.git 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 --- 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; @@ -1008,14 +1008,9 @@ 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;