system/popen: add dpopen/dpclose fd-based interface and no-shell mode#3515
Open
cuiziweizw wants to merge 3 commits into
Open
system/popen: add dpopen/dpclose fd-based interface and no-shell mode#3515cuiziweizw wants to merge 3 commits into
cuiziweizw wants to merge 3 commits into
Conversation
Add dpopen()/dpclose() as the descriptor-based counterpart of popen()/pclose(), analogous to how dprintf() relates to fprintf(). dpopen() returns a raw file descriptor instead of a FILE stream, avoiding the stdio.h dependency for callers that only need an fd. Refactor popen() as a thin wrapper: dpopen() + fdopen() + FILE container. All pipe creation and process spawning logic now lives in dpopen.c. Also remove the hard dependency on NSH_LIBRARY from SYSTEM_POPEN. When NSH is available, commands are executed through sh -c with full shell syntax support. When NSH is not available, commands are split by whitespace and executed directly via posix_spawnp(). Add CONFIG_SYSTEM_POPEN_MAXARGUMENTS (default 7) to control the argv array size for the no-shell path. Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
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>
Add tests for popen()/pclose() and dpopen()/dpclose() that work in both shell (NSH) and no-shell (direct posix_spawnp) modes. The test binary doubles as its own target via the --echo sub-command. Tests: 1-4: popen - basic read, multi-arg, pclose, invalid mode 5-8: dpopen - basic read, multi-arg, dpclose, invalid mode Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
xiaoxiang781216
approved these changes
Jun 1, 2026
acassis
approved these changes
Jun 1, 2026
Contributor
|
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
dpopen()/dpclose()as the descriptor-basedcounterpart of
popen()/pclose(), analogous to howdprintf()relates to
fprintf().dpopen()returns a raw file descriptorinstead of a
FILEstream, avoiding thestdio.hdependency forcallers that only need an fd.
popen()is refactored as a thinwrapper:
dpopen()+fdopen()+ FILE container.posix_spawnp(). The harddependency on
NSH_LIBRARYis removed; when NSH is unavailable,commands are split by whitespace and executed directly. Adds
CONFIG_SYSTEM_POPEN_MAXARGUMENTS(default 7).(NSH) and no-shell modes.
Depends on the header declarations in the companion nuttx PR:
apache/nuttx#19008
Testing
Ran the new
testing/libc/popentest in both shell and no-shellconfigurations; all 8 cases pass.