mirror of
https://github.com/git/git.git
synced 2026-01-18 14:44:28 +00:00
mingw: explicitly specify with which cmd to prefix the cmdline
The main idea of this patch is that even if we have to look up the absolute path of the script, if only the basename was specified as argv[0], then we should use that basename on the command line, too, not the absolute path. This patch will also help with the upcoming patch where we automatically substitute "sh ..." by "busybox sh ..." if "sh" is not in the PATH but "busybox" is: we will do that by substituting the actual executable, but still keep prepending "sh" to the command line. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
@@ -1606,8 +1606,8 @@ static int is_msys2_sh(const char *cmd)
|
||||
}
|
||||
|
||||
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
|
||||
const char *dir,
|
||||
int prepend_cmd, int fhin, int fhout, int fherr)
|
||||
const char *dir, const char *prepend_cmd,
|
||||
int fhin, int fhout, int fherr)
|
||||
{
|
||||
static int restrict_handle_inheritance = 1;
|
||||
STARTUPINFOEXW si;
|
||||
@@ -1681,9 +1681,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
|
||||
/* concatenate argv, quoting args as we go */
|
||||
strbuf_init(&args, 0);
|
||||
if (prepend_cmd) {
|
||||
char *quoted = (char *)quote_arg(cmd);
|
||||
char *quoted = (char *)quote_arg(prepend_cmd);
|
||||
strbuf_addstr(&args, quoted);
|
||||
if (quoted != cmd)
|
||||
if (quoted != prepend_cmd)
|
||||
free(quoted);
|
||||
}
|
||||
for (; *argv; argv++) {
|
||||
@@ -1841,7 +1841,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
|
||||
return (pid_t)pi.dwProcessId;
|
||||
}
|
||||
|
||||
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
|
||||
static pid_t mingw_spawnv(const char *cmd, const char **argv,
|
||||
const char *prepend_cmd)
|
||||
{
|
||||
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
|
||||
}
|
||||
@@ -1869,14 +1870,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
|
||||
pid = -1;
|
||||
}
|
||||
else {
|
||||
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
|
||||
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
|
||||
fhin, fhout, fherr);
|
||||
free(iprog);
|
||||
}
|
||||
argv[0] = argv0;
|
||||
}
|
||||
else
|
||||
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
|
||||
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
|
||||
fhin, fhout, fherr);
|
||||
free(prog);
|
||||
}
|
||||
@@ -1902,7 +1903,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
|
||||
ALLOC_ARRAY(argv2, argc + 1);
|
||||
argv2[0] = (char *)cmd; /* full path to the script file */
|
||||
memcpy(&argv2[1], &argv[1], sizeof(*argv) * argc);
|
||||
pid = mingw_spawnv(prog, argv2, 1);
|
||||
pid = mingw_spawnv(prog, argv2, interpr);
|
||||
if (pid >= 0) {
|
||||
int status;
|
||||
if (waitpid(pid, &status, 0) < 0)
|
||||
@@ -1922,7 +1923,7 @@ int mingw_execv(const char *cmd, char *const *argv)
|
||||
if (!try_shell_exec(cmd, argv)) {
|
||||
int pid, status;
|
||||
|
||||
pid = mingw_spawnv(cmd, (const char **)argv, 0);
|
||||
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
|
||||
if (pid < 0)
|
||||
return -1;
|
||||
if (waitpid(pid, &status, 0) < 0)
|
||||
|
||||
Reference in New Issue
Block a user