Skip to content

system/nxinit: add property-based action triggers - #3726

Merged
xiaoxiang781216 merged 6 commits into
apache:masterfrom
JianyuWang0623:nxinit-action-triggers
Aug 15, 2026
Merged

system/nxinit: add property-based action triggers#3726
xiaoxiang781216 merged 6 commits into
apache:masterfrom
JianyuWang0623:nxinit-action-triggers

Conversation

@JianyuWang0623

Copy link
Copy Markdown
Contributor

Note: Please adhere to Contributing Guidelines.

Summary

Extend init actions from bare event names to a property-based trigger model:

on <event> [&& <event>]*

<event> is a name or property:key=value (fnmatch, != inverts). Adds a
setprop builtin and a pluggable poller backend (property_simple.c). Bare
names map to default==<name>, so existing on <event> rc files keep working.
Includes three fixes to the new parser and matcher: event parsing loss,
multi-event AND semantics, and size_t index underflow.

Impact

  • rc files: new on property:... syntax and setprop; old on <event> unchanged.
  • Kconfig: ..._ACTION_MANAGER_EVENT_MAX (32) → ..._ACTION_EVENTS_MAX (default 1, range 1..64); configs setting the old symbol must be updated.
  • Build: adds property_simple.c. No hardware or security impact.

Testing

on boot
   setprop key_test
   setprop key_test value_test  /* property changed and matched */
   trigger event_test

on event_test && property:key_test=value_test
   echo "on event_test, property changed!"

on property:key_test=value_test
   echo "property changed!"

tools/checkpatch.sh -f passes on all changed files.

fangpeina and others added 6 commits August 14, 2026 20:51
Add the property backend and a setprop builtin so that setting a
property can feed action triggers.  property_simple.c provides a minimal
init_property_*() implementation whose init_property_set() forwards the
key/value pair to init_action_trigger_event(), and init.c wires the
property poller into the init poll loop.

Signed-off-by: fangpeina <fangpeina@xiaomi.com>
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Previously only supported event trigger, now added support for
action triggers (property setting).

Steps to enable action triggers:
  - Define all init_property_*() interfaces declared in this file.
  - Data structures or functions that will likely be used:
    - struct action_trigger_s
    - init_action_for_every()

Example
  ```
  on boot
     setprop key_test
     setprop key_test value_test  /* property changed and matched */
     trigger event_test

  on event_test && property:key_test=value_test
     echo "on event_test, property changed!"

  on property:key_test=value_test
     echo "property changed!"
  ```

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
init.rc

  on boot && property:sys.boot.reason!=bootloader
     echo "On boot, the reason is not BL."

Before fixing

    init_main: action 0x40436120
    init_main:   sys.boot.reason!=bootloader
    init_main:   argv[0] 'echo'
    init_main:   argv[1] 'On boot, the reason is not BL.'

After fixing

    init_main: action 0x40436120
    init_main:   sys.boot.reason!=bootloader
  + init_main:   default==boot
    init_main:   argv[0] 'echo'
    init_main:   argv[1] 'On boot, the reason is not BL.'

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
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>
Decrementing i when it's 0 in "for (; i >= 0; i--)" causes size_t
underflow to a huge value.

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
The `on <event>` action re-executed on every property poll because the
event pending flag was sticky: event_callback returned the same non-zero
pending value whether the event had just changed or had stayed satisfied
from an earlier change. init_action_foreach_event could not distinguish
an edge from a steady state and re-enqueued the action each round
(board_netinit ran 262 times per boot).

Introduce a three-state result (EVENT_STATE_UNSATISFIED / SATISFIED /
TRIGGERED). event_callback now returns TRIGGERED only on the edge where
pending flips false -> true. foreach folds per-event states into a
product clamped to TRIGGERED, enqueuing the action only when every event
is satisfied AND at least one fired this round.

Assisted-by: GitHubCopilot:claude-4.8-opus
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>

@acassis acassis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JianyuWang0623 nice! Please update the Documentation

@xiaoxiang781216
xiaoxiang781216 merged commit 3328bbb into apache:master Aug 15, 2026
20 of 42 checks passed
xiaoxiang781216 pushed a commit to apache/nuttx that referenced this pull request Aug 17, 2026
The Triggers section previously stated that action (property) triggers
were not yet implemented; they are supported now, so describe the
fnmatch value matching and the edge-triggered semantics of on <event>.
The Examples section used the stale CONFIG_SYSTEM_INIT_* prefix and now
uses CONFIG_SYSTEM_NXINIT_* together with a property trigger example.

This documents the behavior added in
apache/nuttx-apps#3726.

Assisted-by: GitHubCopilot:claude-opus-4.8
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants