system/nxinit: increase SERVICE_ARGS_MAX default and add 'set' builtin - #3758
Merged
acassis merged 2 commits intoAug 28, 2026
Merged
Conversation
JianyuWang0623
marked this pull request as draft
August 26, 2026 14:56
JianyuWang0623
marked this pull request as ready for review
August 26, 2026 15:46
xiaoxiang781216
approved these changes
Aug 26, 2026
This comment has been minimized.
This comment has been minimized.
The previous default of 8 is insufficient for services with many arguments (e.g. ptpd needs 10 argv slots). When exceeded, argv lacks a NULL terminator, causing posix_spawnp to read out of bounds. Increase default to 16 to prevent argument truncation for typical daemon services. Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Previously, 'set KEY VALUE' in init.rc was not recognized as a builtin command. It fell through to posix_spawnp(), which ran it in a temporary child shell. The environment variable was set only in the child process and lost when it exited, so services started afterward never inherited it. Register cmd_set as an init builtin that calls setenv(key, value, 1) directly in the init process. The command takes exactly 2 arguments (key and value). All code is guarded by CONFIG_DISABLE_ENVIRON so it compiles out when environment support is disabled. Since child processes inherit init's environment, 'set TZ Asia/Shanghai' in init.rc now correctly propagates to all subsequently started services. Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
JianyuWang0623
force-pushed
the
nxinit-args-max-and-set-builtin
branch
from
August 27, 2026 12:11
9015fd8 to
2f4019d
Compare
xiaoxiang781216
approved these changes
Aug 28, 2026
acassis
approved these changes
Aug 28, 2026
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
Two independent, low-risk fixes carried over from the internal (vela) fork of this component:
SYSTEM_NXINIT_SERVICE_ARGS_MAXdefault from 8 to 16. The previous default is insufficient for services with many arguments (e.g. ptpd needs 10 argv slots). When exceeded, argv lacks a NULL terminator, causingposix_spawnpto read out of bounds.set KEY VALUEbuiltin command. Previouslysetin init.rc fell through toposix_spawnp(), which ran it in a temporary child shell — the environment variable was set only in that child and lost when it exited, so later services never inherited it.cmd_setnow callssetenv()directly in the init process, guarded byCONFIG_DISABLE_ENVIRON, so child processes (which inherit init's environment) see it correctly.Impact
Testing
Built for
esp32p4-function-ev-board:nsh(CONFIG_SYSTEM_NXINIT=y) with the actual toolchain (riscv-none-elf-gcc):Verified via
nm nuttxthatcmd_setis linked into the image, and confirmedCONFIG_SYSTEM_NXINIT_SERVICE_ARGS_MAX=16takes effect in the generated.config.Ran
nxstyleon the changed file (builtin.c) with no violations.Runtime verification (esp32p4-pico-wifi-wareshare, MAC
80:f1:b2:d0:84:c4,/dev/ttyACM3)The lckfb-szpi-esp32s3 board normally used for hardware verification was not reachable on any
/dev/ttyACM*//dev/ttyUSB*this time (esptool.py read_macfailed on all of them, likely not connected). Both changes in this PR live inapps/system/nxinitand are board-agnostic, so an esp32p4 board was used as an equivalent target.Flashed the branch build and captured the nsh serial console:
init_main(nxinit, PID 2) is the parent ofsh(PID 3), confirming nxinit is functioning correctly as system init withCONFIG_SYSTEM_NXINIT_SERVICE_ARGS_MAX=16in the running firmware.To exercise the new
setbuiltin specifically, a temporaryset NXINIT_SET_TEST hello_from_set_builtinline was added toinit.rc'son initblock (build/flash/verify only — reverted afterward, not part of this PR):This confirms
set KEY VALUEis parsed and executed from init.rc,setenv()takes effect in the init process, and the spawned child (sh) inherits the variable. After this check, theinit.rcchange was reverted (git statusclean on bothnuttxandappsrepos) — no code in this PR was altered.