mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-01 20:29:00 +00:00
When NSH_LIBRARY is not available, dpopen()/popen() can still execute commands by splitting the command string by whitespace and calling posix_spawnp() directly. Shell syntax (pipes, redirects, globbing) is not supported in this mode. Add CONFIG_SYSTEM_POPEN_MAXARGUMENTS (default 7) to control the argv array size for the no-shell path. Remove the hard dependency on NSH_LIBRARY from SYSTEM_POPEN so the feature can be used in minimal configurations without a shell. Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
73 lines
2.4 KiB
Text
73 lines
2.4 KiB
Text
#
|
|
# For a description of the syntax of this configuration file,
|
|
# see the file kconfig-language.txt in the NuttX tools repository.
|
|
#
|
|
|
|
config SYSTEM_POPEN
|
|
bool "popen()/pclose()/dpopen()/dpclose() Functions"
|
|
default n
|
|
select SCHED_WAITPID
|
|
depends on PIPES
|
|
---help---
|
|
Enable support for the popen(), pclose(), dpopen(), and
|
|
dpclose() interfaces.
|
|
|
|
dpopen()/dpclose() are the descriptor-based counterparts
|
|
of popen()/pclose(), analogous to how dprintf() relates
|
|
to fprintf(). They return a raw file descriptor instead
|
|
of a FILE stream, avoiding the stdio.h dependency.
|
|
|
|
popen()/pclose() are thin wrappers around dpopen()/dpclose()
|
|
that additionally wrap the fd in a FILE stream.
|
|
|
|
When NSH is available (NSH_LIBRARY), commands are executed
|
|
through the shell (sh -c command), supporting full shell
|
|
syntax including pipes, redirects, and globbing.
|
|
|
|
When NSH is not available, commands are executed directly
|
|
via posix_spawnp(). The command string must be a simple
|
|
"program arg1 arg2" form without shell syntax.
|
|
|
|
if SYSTEM_POPEN
|
|
|
|
config SYSTEM_POPEN_SHPATH
|
|
string "Path to shell command"
|
|
default "/bin/sh"
|
|
depends on (SYSTEM_NSH=m || BUILD_KERNEL) && NSH_LIBRARY
|
|
---help---
|
|
This is the full path to the program in a mounted file system that
|
|
implements the system() command. That is, a program that starts the
|
|
NSH shell, executes one command (in argv[1]), then exits.
|
|
|
|
config SYSTEM_POPEN_STACKSIZE
|
|
int "Shell stack size"
|
|
default DEFAULT_TASK_STACKSIZE
|
|
---help---
|
|
The size of stack allocated for the shell.
|
|
|
|
NOTE: I needed to set the stack size quite large to get this example
|
|
working on the simulated target (perhaps because of the 64-bit
|
|
stack? Or perhaps that is a sneak call into the host libc that I
|
|
have not caught). I assume that a smaller stack would be okay on
|
|
real hardware, but I have not yet verified that.
|
|
|
|
config SYSTEM_POPEN_PRIORITY
|
|
int "Shell priority"
|
|
default 100
|
|
---help---
|
|
The priority of the shell.
|
|
|
|
config SYSTEM_POPEN_MAXARGUMENTS
|
|
int "Maximum number of command arguments (no-shell mode)"
|
|
default 7
|
|
depends on !NSH_LIBRARY
|
|
---help---
|
|
When NSH is not available, dpopen()/popen() splits the command
|
|
string by whitespace into an argv array. This sets the maximum
|
|
number of arguments (excluding the program name and the
|
|
terminating NULL).
|
|
|
|
This is analogous to CONFIG_NSH_MAXARGUMENTS but applies
|
|
only to the no-shell path.
|
|
|
|
endif
|