aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2009-04-23 03:03:05 +1000
committerNguyễn Thái Ngọc Duy <pclouds@gmail.com>2009-04-23 04:44:32 +1000
commitef9b20fa7904ee5f72e3a759934560226360842d (patch)
tree301a6ddd48dd547dd4fd64b7324dfa8f5ba39265
parent6d451b23a689aa423a885b5fd876cd2316d84e3b (diff)
downloadbusybox-w32-ef9b20fa7904ee5f72e3a759934560226360842d.tar.gz
busybox-w32-ef9b20fa7904ee5f72e3a759934560226360842d.tar.bz2
busybox-w32-ef9b20fa7904ee5f72e3a759934560226360842d.zip
mingw.c: prefer busybox sh instead
-rw-r--r--libbb/mingw.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/libbb/mingw.c b/libbb/mingw.c
index 181999f3f..1a9f35f4d 100644
--- a/libbb/mingw.c
+++ b/libbb/mingw.c
@@ -1,6 +1,7 @@
1#include "../git-compat-util.h" 1#include "../git-compat-util.h"
2#include "win32.h" 2#include "win32.h"
3#include "../strbuf.h" 3#include "../strbuf.h"
4#include "run-command.h"
4 5
5unsigned int _CRT_fmode = _O_BINARY; 6unsigned int _CRT_fmode = _O_BINARY;
6 7
@@ -803,6 +804,26 @@ static pid_t mingw_spawnve(const char *cmd, const char **argv, char **env,
803 return (pid_t)pi.hProcess; 804 return (pid_t)pi.hProcess;
804} 805}
805 806
807static int spawn_gitbox_shell(struct child_process *cp, const char *cmd, const char **argv)
808{
809 int argc = 0;
810 const char **argv2;
811 int ret;
812
813 while (argv[argc]) argc++;
814 argv2 = xmalloc(sizeof(*argv) * (argc+3));
815 argv2[0] = CONFIG_BUSYBOX_EXEC_PATH;
816 argv2[1] = "sh";
817 argv2[2] = cmd;
818 memcpy(&argv2[3], &argv[1], sizeof(*argv)*argc);
819
820 memset(cp, 0, sizeof(*cp));
821 cp->argv = argv2;
822 ret = start_command(cp);
823 free(argv2);
824 return ret;
825}
826
806pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env) 827pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env)
807{ 828{
808 pid_t pid; 829 pid_t pid;
@@ -816,6 +837,10 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env)
816 else { 837 else {
817 const char *interpr = parse_interpreter(prog); 838 const char *interpr = parse_interpreter(prog);
818 839
840 if (interpr && !strcmp(interpr, "sh")) {
841 struct child_process cp;
842 return spawn_gitbox_shell(&cp, prog, argv) ? -1 : cp.pid;
843 }
819 if (interpr) { 844 if (interpr) {
820 const char *argv0 = argv[0]; 845 const char *argv0 = argv[0];
821 char *iprog = path_lookup(interpr, path, 1); 846 char *iprog = path_lookup(interpr, path, 1);
@@ -849,7 +874,16 @@ static int try_shell_exec(const char *cmd, char *const *argv, char **env)
849 return 0; 874 return 0;
850 path = get_path_split(); 875 path = get_path_split();
851 prog = path_lookup(interpr, path, 1); 876 prog = path_lookup(interpr, path, 1);
852 if (prog) { 877 if (!prog) {
878 free_path_split(path);
879 return 0;
880 }
881 /* prefer gitbox for shell */
882 if (!strcmp(interpr, "sh")) {
883 struct child_process cp;
884 return spawn_gitbox_shell(&cp, prog, argv) ? 1 : WEXITSTATUS(finish_command(&cp));
885 }
886 else {
853 int argc = 0; 887 int argc = 0;
854 const char **argv2; 888 const char **argv2;
855 while (argv[argc]) argc++; 889 while (argv[argc]) argc++;