From d1da09ea7a88cabdce417041ffa2018b7516de0c Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sun, 18 Feb 2018 12:23:48 +0000 Subject: 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. --- win32/popen.c | 14 ++++++++++++-- 1 file 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 @@ #include #include "libbb.h" +#include "NUM_APPLETS.h" typedef struct { PROCESS_INFORMATION piProcInfo; @@ -90,13 +91,22 @@ FILE *mingw_popen(const char *cmd, const char *mode) } } - len = strlen(cmd) + 10 + count; + len = strlen(bb_busybox_exec_path) + strlen(cmd) + 32 + count; if ( (cmd_buff=malloc(len)) == NULL ) { return NULL; } +#if (ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE) && \ + NUM_APPLETS > 1 + if (find_applet_by_name("sh") >= 0) { + strcpy(cmd_buff, bb_busybox_exec_path); + strcat(cmd_buff, " --busybox sh -c \""); + } + else +#endif + strcpy(cmd_buff, "sh -c \""); + /* escape double quotes */ - strcpy(cmd_buff, "sh -c \""); for ( s=cmd,t=cmd_buff+strlen(cmd_buff); *s; ++s ) { if ( *s == '"' ) { *t++ = '\\'; -- cgit v1.2.3-55-g6feb