This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit 5b6299100fe141cf4ab78d2e547746cd6b660863
Author: wangjianyu3 <[email protected]>
AuthorDate: Tue Dec 9 11:51:35 2025 +0800

    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 <[email protected]>
---
 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;

Reply via email to