Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/popen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
# ##############################################################################

if(CONFIG_SYSTEM_POPEN)
target_sources(apps PRIVATE popen.c)
target_sources(apps PRIVATE dpopen.c popen.c)
endif()
40 changes: 34 additions & 6 deletions system/popen/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,36 @@
#

config SYSTEM_POPEN
bool "popen()/pclose() Functions"
bool "popen()/pclose()/dpopen()/dpclose() Functions"
default n
select SCHED_WAITPID
depends on NSH_LIBRARY && PIPES
depends on PIPES
---help---
Enable support for the popen() and pclose() interfaces.
This will support execution of NSH commands from C code with
pipe communications with the shell.
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
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
Expand All @@ -42,4 +57,17 @@ config SYSTEM_POPEN_PRIORITY
---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
4 changes: 2 additions & 2 deletions system/popen/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

include $(APPDIR)/Make.defs

# popen()/pclose functions
# dpopen()/dpclose() core and popen()/pclose() FILE wrappers

CSRCS = popen.c
CSRCS = dpopen.c popen.c

include $(APPDIR)/Application.mk
Loading
Loading