[PATCH 1/2] run-command.c: Define SHELL_PATH macro for use in prepare_shell_cmd
- From
Ben Walton <bwalton@artsci.utoronto.ca>
- Date
- Mar 25, 2012, 12:31 UTC
- Message-ID
- <1332678696-4001-2-git-send-email-bwalton@artsci.utoronto.ca>
- In-Reply-To
- <1332678696-4001-1-git-send-email-bwalton@artsci.utoronto.ca>
The shell spawned in run-command.c:prepare_shell_cmd was hard coded to 'sh'. Instead, make this a macro named SHELL_PATH so that it can be overridden by the build system. Use 'sh' as the default to preserve original behaviour and ensure that a value is always set.
This avoids a situation where some commands were spawned using a different shell than the one configured at build time. Previously, it was possible for things to be executed by a non-POSIX shell depending on the user's PATH.
Signed-off-by: Ben Walton <bwalton@artsci.utoronto.ca> --- run-command.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/run-command.c b/run-command.c index 1db8abf..f005a31 100644 --- a/run-command.c +++ b/run-command.c @@ -4,6 +4,10 @@ #include "sigchain.h" #include "argv-array.h" +#ifndef SHELL_PATH +# define SHELL_PATH "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)
-- 1.7.5.4