Skip to content

Commit

Permalink
Merge branch 'bw/spawn-via-shell-path'
Browse files Browse the repository at this point in the history
"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
  • Loading branch information
Junio C Hamano committed Apr 16, 2012
2 parents 0f3ddd4 + b3e34dd commit fa0ba72
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 5 additions & 1 deletion run-command.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fa0ba72

Please sign in to comment.