From 5b6299100fe141cf4ab78d2e547746cd6b660863 Mon Sep 17 00:00:00 2001 From: wangjianyu3 Date: Tue, 9 Dec 2025 11:51:35 +0800 Subject: [PATCH] system/nxinit: Fix multi-event action triggering Action triggered on any event before this fix (e.g. both opposite actions in init.rc below triggered when event "boot" triggered). init.rc on boot && property:sys.boot.reason=bootloader echo "On boot, the reason is BL." on boot && property:sys.boot.reason!=bootloader echo "On boot, the reason is not BL." Signed-off-by: wangjianyu3 --- system/nxinit/action.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/system/nxinit/action.c b/system/nxinit/action.c index 66c97d55d..eea662001 100644 --- a/system/nxinit/action.c +++ b/system/nxinit/action.c @@ -167,6 +167,7 @@ static int parse_event(FAR char *buf, FAR struct action_event_s *events, events[i].key = strdup(key); events[i].value = strdup(value); + events[i].pending = false; if (events[i].key && events[i].value) { @@ -203,21 +204,19 @@ static int event_callback(FAR struct action_manager_s *am, { struct event_arg_s *arg = argument; - if (strcmp(arg->key, event->key)) + if (!strcmp(arg->key, event->key)) { - return 0; - } - - if (event->invert != fnmatch(event->value, arg->value, 0)) - { - event->pending = false; - } - else if (!event->pending) - { - event->pending = true; - init_debug("Trigger %s%s%s", event->key, - event->invert ? "!=" : "==", - event->value); + if (event->invert != fnmatch(event->value, arg->value, 0)) + { + event->pending = false; + } + else if (!event->pending) + { + event->pending = true; + init_debug("Trigger %s%s%s", event->key, + event->invert ? "!=" : "==", + event->value); + } } return event->pending; @@ -233,11 +232,12 @@ int init_action_foreach_event(FAR struct action_manager_s *am, { FAR struct action_s *a; size_t i; + size_t m; int ret = 0; list_for_every_entry(&am->actions, a, struct action_s, node) { - for (i = 0; i < nitems(a->events) && a->events[i].key; i++) + for (i = 0, m = 0; i < nitems(a->events) && a->events[i].key; i++) { ret = cb(am, a, &a->events[i], arg); if (ret < 0) @@ -246,9 +246,14 @@ int init_action_foreach_event(FAR struct action_manager_s *am, } else if (ret > 0) { - add_ready(am, a); + m++; } } + + if (i > 0 && i == m) + { + add_ready(am, a); + } } return ret;