nuttx-apps/system/nxinit
wangjianyu3 bc0ed23a5d system/nxinit: add a per-service "console" option
Services started by nxinit (e.g. "sh") do not open a console device on
their own, unlike nsh_main, which explicitly does so via
nsh_consolemain()/nsh_waitusbready() for USB gadget consoles
(CDC-ACM/PL2303). When such a board switches its top-level init from
nsh_main to nxinit, no code path ever registers/connects the USB
console gadget, and a service that just execs a plain "sh" inherits
whatever (invalid, for a USB gadget console not yet opened at the time
the idle task file descriptors are set up) stdio nxinit itself has.

Add a "console [<device>]" service option: a service declared with it
gets the given device (CONFIG_SYSTEM_NXINIT_CONSOLE_DEV, "/dev/console"
by default, if no device is given) opened and dup'd onto its stdin,
stdout and stderr via posix_spawn_file_actions before it is spawned.
This does not depend on nsh being enabled at all.

For a USB gadget console, the device does not exist until the gadget
is actually registered; boards using one are expected to bring it up
themselves before any service using "console" is started (e.g. via an
"exec -- sercon" action in their init.rc, since apps/system/cdcacm
already implements exactly that registration step and does not depend
on nxinit or nsh either).

console_file_actions() runs after the previous commit's time_started
update, so a failure to build the console's file actions is covered by
the same up to date timestamp - no separate clock_gettime() call is
needed on this failure path.

Covered by a new unit test, test_nxinit_service_console_option, that
exercises the option with and without an explicit device, and confirms
services without the option are left untouched.

Assisted-by: Kiro:claude-sonnet-5
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2026-09-10 23:12:06 +08:00
..
test system/nxinit: add a per-service "console" option 2026-09-10 23:12:06 +08:00
action.c system/nxinit: support compound command execution 2026-08-26 10:00:02 -03:00
action.h system/nxinit: support compound command execution 2026-08-26 10:00:02 -03:00
builtin.c system/nxinit: add 'set' builtin command for environment variables 2026-08-28 09:30:53 -03:00
builtin.h system/nxinit: Add NuttX Init 2026-05-27 17:20:07 -03:00
CMakeLists.txt system/nxinit: add cmocka unit tests for parser/action/service 2026-08-28 09:33:47 -03:00
import.c system/nxinit: Fix missing check for import argument 2026-06-05 09:43:45 +08:00
import.h system/nxinit: Add NuttX Init 2026-05-27 17:20:07 -03:00
init.c system/nxinit: fix unkown -> unknown typo in resetcause[] 2026-08-26 10:00:02 -03:00
init.h system/nxinit: Add setprop support for action 2026-08-15 18:51:45 +08:00
Kconfig system/nxinit: add a per-service "console" option 2026-09-10 23:12:06 +08:00
Make.defs system/nxinit: Add NuttX Init 2026-05-27 17:20:07 -03:00
Makefile system/nxinit: add cmocka unit tests for parser/action/service 2026-08-28 09:33:47 -03:00
parser.c system/nxinit: add cmocka unit tests for parser/action/service 2026-08-28 09:33:47 -03:00
parser.h system/nxinit: add cmocka unit tests for parser/action/service 2026-08-28 09:33:47 -03:00
property.h system/nxinit: Add setprop support for action 2026-08-15 18:51:45 +08:00
property_simple.c system/nxinit: Add setprop support for action 2026-08-15 18:51:45 +08:00
service.c system/nxinit: add a per-service "console" option 2026-09-10 23:12:06 +08:00
service.h system/nxinit: add a per-service "console" option 2026-09-10 23:12:06 +08:00