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 <wangjianyu3@xiaomi.com>
This commit is contained in:
wangjianyu3 2025-12-09 11:51:35 +08:00 committed by Xiang Xiao
parent 1290acf35c
commit 5b6299100f

View file

@ -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;