rcS: avoid duplicate pending "running" calls
authorFelix Fietkau <nbd@nbd.name>
Thu, 13 Mar 2025 10:21:13 +0000 (11:21 +0100)
committerFelix Fietkau <nbd@nbd.name>
Thu, 13 Mar 2025 10:21:15 +0000 (11:21 +0100)
Since those can be triggered by instance restarts now, and since the calls
can wait for their service to be active, suppress duplicate concurrent script
calls in case of rapid consecutive crashes.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
rcS.c

diff --git a/rcS.c b/rcS.c
index 2851fae99bef13085cd047912d804c8c45f40114..bfaf50b15bb125d32dff31f839c6b73ce905c709 100644 (file)
--- a/rcS.c
+++ b/rcS.c
@@ -125,6 +125,16 @@ static void q_initd_complete(struct runqueue *q, struct runqueue_task *p)
        free(s);
 }
 
+static bool find_runqueue_list_entry(struct list_head *list, char *file, char *param)
+{
+       struct initd *s;
+
+       list_for_each_entry(s, list, proc.task.list.list)
+               if (!strcmp(s->file, file) && !strcmp(s->param, param))
+                       return true;
+       return false;
+}
+
 static void add_initd(struct runqueue *q, char *file, char *param)
 {
        static const struct runqueue_task_type initd_type = {
@@ -135,6 +145,11 @@ static void add_initd(struct runqueue *q, char *file, char *param)
        struct initd *s;
        char *p, *f;
 
+       if (!strcmp(param, "running") &&
+           (find_runqueue_list_entry(&q->tasks_active.list, file, param) ||
+            find_runqueue_list_entry(&q->tasks_inactive.list, file, param)))
+               return;
+
        s = calloc_a(sizeof(*s), &f, strlen(file) + 1, &p, strlen(param) + 1);
        if (!s) {
                ERROR("Out of memory in %s.\n", file);