diff options
author | Ron Yorston <rmy@pobox.com> | 2018-02-18 12:23:48 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-02-18 12:23:48 +0000 |
commit | d1da09ea7a88cabdce417041ffa2018b7516de0c (patch) | |
tree | cb042c4f3bc01807ee00eaac09d4e707b8ed4460 | |
parent | 96c9c0044f3c0a8e3b23e1eb05a86a6222cb741c (diff) | |
download | busybox-w32-d1da09ea7a88cabdce417041ffa2018b7516de0c.tar.gz busybox-w32-d1da09ea7a88cabdce417041ffa2018b7516de0c.tar.bz2 busybox-w32-d1da09ea7a88cabdce417041ffa2018b7516de0c.zip |
win32: use built-in shell for popen, if possible
popen uses the shell to run the command provided. If BusyBox has
been configured appropriately use the built-in shell for this.
- Currently the only user of popen in busybox-w32 is awk, which
uses it when piping to or from commands.
- If the command is available as an applet the shell will use it.
If a different version of the program is required the command
will need to specify the full path.
- This change means that popen will work even if no shell is
present on the path.
- Since the binary may have been run as sh.exe or awk.exe it's
necessary to use the magic --busybox option.
-rw-r--r-- | win32/popen.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/win32/popen.c b/win32/popen.c index 6b8e52ca9..59f5ca9f0 100644 --- a/win32/popen.c +++ b/win32/popen.c | |||
@@ -1,5 +1,6 @@ | |||
1 | #include <fcntl.h> | 1 | #include <fcntl.h> |
2 | #include "libbb.h" | 2 | #include "libbb.h" |
3 | #include "NUM_APPLETS.h" | ||
3 | 4 | ||
4 | typedef struct { | 5 | typedef struct { |
5 | PROCESS_INFORMATION piProcInfo; | 6 | PROCESS_INFORMATION piProcInfo; |
@@ -90,13 +91,22 @@ FILE *mingw_popen(const char *cmd, const char *mode) | |||
90 | } | 91 | } |
91 | } | 92 | } |
92 | 93 | ||
93 | len = strlen(cmd) + 10 + count; | 94 | len = strlen(bb_busybox_exec_path) + strlen(cmd) + 32 + count; |
94 | if ( (cmd_buff=malloc(len)) == NULL ) { | 95 | if ( (cmd_buff=malloc(len)) == NULL ) { |
95 | return NULL; | 96 | return NULL; |
96 | } | 97 | } |
97 | 98 | ||
99 | #if (ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE) && \ | ||
100 | NUM_APPLETS > 1 | ||
101 | if (find_applet_by_name("sh") >= 0) { | ||
102 | strcpy(cmd_buff, bb_busybox_exec_path); | ||
103 | strcat(cmd_buff, " --busybox sh -c \""); | ||
104 | } | ||
105 | else | ||
106 | #endif | ||
107 | strcpy(cmd_buff, "sh -c \""); | ||
108 | |||
98 | /* escape double quotes */ | 109 | /* escape double quotes */ |
99 | strcpy(cmd_buff, "sh -c \""); | ||
100 | for ( s=cmd,t=cmd_buff+strlen(cmd_buff); *s; ++s ) { | 110 | for ( s=cmd,t=cmd_buff+strlen(cmd_buff); *s; ++s ) { |
101 | if ( *s == '"' ) { | 111 | if ( *s == '"' ) { |
102 | *t++ = '\\'; | 112 | *t++ = '\\'; |