Merge branch 'bw/spawn-via-shell-path'
authorJunio C Hamano <gitster@pobox.com>
Mon, 16 Apr 2012 19:42:54 +0000 (12:42 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 Apr 2012 19:42:55 +0000 (12:42 -0700)
"sh" on the user's PATH may be utterly broken on some systems;
consistently use SHELL_PATH even from inside run-command API.

By Ben Walton
* bw/spawn-via-shell-path:
Use SHELL_PATH from build system in run_command.c:prepare_shell_cmd

Makefile
run-command.c
index be1957a5e986d2e0581123dfe4e0eeb6702c13dc..abee43e264fe3e8fd94c71bea408a2338a5c3dab 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1849,6 +1849,13 @@ DEFAULT_PAGER_CQ_SQ = $(subst ','\'',$(DEFAULT_PAGER_CQ))
 BASIC_CFLAGS += -DDEFAULT_PAGER='$(DEFAULT_PAGER_CQ_SQ)'
 endif
 
+ifdef SHELL_PATH
+SHELL_PATH_CQ = "$(subst ",\",$(subst \,\\,$(SHELL_PATH)))"
+SHELL_PATH_CQ_SQ = $(subst ','\'',$(SHELL_PATH_CQ))
+
+BASIC_CFLAGS += -DSHELL_PATH='$(SHELL_PATH_CQ_SQ)'
+endif
+
 ALL_CFLAGS += $(BASIC_CFLAGS)
 ALL_LDFLAGS += $(BASIC_LDFLAGS)
 
index 1db8abf9843516576f30f8105bbfdd66487db6e1..2af3e0fa520bcd87d241ed7a3601b14232ad94d5 100644 (file)
@@ -4,6 +4,10 @@
 #include "sigchain.h"
 #include "argv-array.h"
 
+#ifndef SHELL_PATH
+# define SHELL_PATH "/bin/sh"
+#endif
+
 struct child_to_clean {
        pid_t pid;
        struct child_to_clean *next;
@@ -90,7 +94,7 @@ static const char **prepare_shell_cmd(const char **argv)
                die("BUG: shell command is empty");
 
        if (strcspn(argv[0], "|&;<>()$`\\\"' \t\n*?[#~=%") != strlen(argv[0])) {
-               nargv[nargc++] = "sh";
+               nargv[nargc++] = SHELL_PATH;
                nargv[nargc++] = "-c";
 
                if (argc < 2)