Repository navigation
system/nxinit: add the wait command - #4135
Draft
JianyuWang0623 wants to merge 1 commit into
Draft
JianyuWang0623 wants to merge 1 commit into
JianyuWang0623 wants to merge 1 commit into
Conversation
An init.rc line could only wait for a file with a fixed sleep: an NSH script can loop "while [ ! -e <path> ]; do usleep ...; done", but NXInit's parser has no loops and an unknown line falls back to "sh -c". Check for <path> with stat() every 10 ms: <timeout> in seconds defaults to 5, and a timeout only warns and continues. Assisted-by: OpenCode:mimo-v2.6-pro Co-authored-by: multica-agent <github@multica.ai> Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
JianyuWang0623
force-pushed
the
jy847-nxinit-wait-only
branch
2 times, most recently
from
November 25, 2026 08:14
fde74ae to
c57f5d6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a
wait <path> [<timeout>]command to NXInit, so an init.rc line can wait for a file instead of sleeping for a fixed time.Without the command, an NSH script waits for a file with a shell loop:
This needs the NSH scripting commands
while,testandusleep; NSH has no single command that waits for a file (itswaittakeswait <pid>...and waits for tasks to exit). NXInit cannot express this wait at all: its parser is line-based with no loops or conditions, and an unknown line falls back tosh -c. So without NSH an rc file can only sleep for a fixed time, which either gives up too early or keeps waiting long after the file is there.For example, a service that registers a device node and a service that needs it:
The documentation change is in apache/nuttx#22301.
Impact
waitchecksstat()for<path>every 10 ms and returns when the file exists;<timeout>is in seconds, may be fractional and defaults to 5, and reaching it only warns and continues. While it waits, the NXInit command loop is blocked. Existing init.rc files and builds are unchanged.Testing
Build Host: Linux x86_64, host gcc (CROSSDEV empty). Target:
sim:nshwithCONFIG_SYSTEM_NXINIT=y,CONFIG_SYSTEM_NXINIT_TEST=y,CONFIG_TESTING_CMOCKA=y,CONFIG_BOARDCTL=y,CONFIG_PM=y, and# CONFIG_SYSTEM_NSH is not set, on current master9cd18a2d6. Run:cd nuttx && timeout 30 ./nuttx < /dev/null.The new cmocka case in the run output:
Suite summary of the same run:
[==========] nxinit_tests: 24 test(s) run.and[ PASSED ] 24 test(s).Waiting for a
/devnode registered late by a service: a oneshot test service sleeps 300 ms and then registers/dev/wait_nodewithregister_driver(), and init.rc runsstart mknode,wait /dev/wait_node 5,exec -- hello(NSH disabled, so every line runs as an NXInit builtin or a spawned Builtin App):Without the patch the same init.rc sends the
waitline tosh -c, which fails without NSH, andhelloruns before the node exists: