diff mbox series

[LEDE-DEV] procd: Fix stop of instance when respawn scheduled

Message ID 20180322170123.22269-2-pavel.merzlyakov@gmail.com
State New
Headers show
Series [LEDE-DEV] procd: Fix stop of instance when respawn scheduled | expand

Commit Message

Pavel Merzlyakov March 22, 2018, 5:01 p.m. UTC
It's give ability to stop respawn of instance
which crashes in the beginning

Signed-off-by: Pavel Merzlyakov <pavel.merzlyakov@gmail.com>
---
 service/instance.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/service/instance.c b/service/instance.c
index ecbb6ea..e2f0ee3 100644
--- a/service/instance.c
+++ b/service/instance.c
@@ -511,6 +511,16 @@  instance_timeout(struct uloop_timeout *t)
 		instance_start(in);
 }
 
+static void
+instance_stopped(struct service_instance *in)
+{
+	struct service *s = in->srv;
+
+	avl_delete(&s->instances.avl, &in->node.avl);
+	instance_free(in);
+	service_stopped(s);
+}
+
 static void
 instance_exit(struct uloop_process *p, int ret)
 {
@@ -532,13 +542,8 @@  instance_exit(struct uloop_process *p, int ret)
 		instance_removepid(in);
 		if (in->restart)
 			instance_start(in);
-		else {
-			struct service *s = in->srv;
-
-			avl_delete(&s->instances.avl, &in->node.avl);
-			instance_free(in);
-			service_stopped(s);
-		}
+		else
+			instance_stopped(in);
 	} else if (in->restart) {
 		instance_start(in);
 	} else if (in->respawn) {
@@ -563,7 +568,7 @@  void
 instance_stop(struct service_instance *in, bool halt)
 {
 	if (!in->proc.pending)
-		return;
+		return instance_stopped(in);
 	in->halt = halt;
 	in->restart = in->respawn = false;
 	kill(in->proc.pid, SIGTERM);