Skip to content

Commit 8f23ef5

Browse files
committed
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 <[email protected]>
1 parent 84a521a commit 8f23ef5

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

compat/mingw.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,8 +1606,8 @@ static int is_msys2_sh(const char *cmd)
16061606
}
16071607

16081608
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1609-
const char *dir,
1610-
int prepend_cmd, int fhin, int fhout, int fherr)
1609+
const char *dir, const char *prepend_cmd,
1610+
int fhin, int fhout, int fherr)
16111611
{
16121612
static int restrict_handle_inheritance = 1;
16131613
STARTUPINFOEXW si;
@@ -1684,9 +1684,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
16841684
/* concatenate argv, quoting args as we go */
16851685
strbuf_init(&args, 0);
16861686
if (prepend_cmd) {
1687-
char *quoted = (char *)quote_arg(cmd);
1687+
char *quoted = (char *)quote_arg(prepend_cmd);
16881688
strbuf_addstr(&args, quoted);
1689-
if (quoted != cmd)
1689+
if (quoted != prepend_cmd)
16901690
free(quoted);
16911691
}
16921692
for (; *argv; argv++) {
@@ -1844,7 +1844,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
18441844
return (pid_t)pi.dwProcessId;
18451845
}
18461846

1847-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
1847+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
1848+
const char *prepend_cmd)
18481849
{
18491850
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
18501851
}
@@ -1872,14 +1873,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
18721873
pid = -1;
18731874
}
18741875
else {
1875-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
1876+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
18761877
fhin, fhout, fherr);
18771878
free(iprog);
18781879
}
18791880
argv[0] = argv0;
18801881
}
18811882
else
1882-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
1883+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
18831884
fhin, fhout, fherr);
18841885
free(prog);
18851886
}
@@ -1907,7 +1908,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
19071908
argv2[0] = (char *)cmd; /* full path to the script file */
19081909
memcpy(&argv2[1], &argv[1], sizeof(*argv) * argc);
19091910
exec_id = trace2_exec(prog, argv2);
1910-
pid = mingw_spawnv(prog, argv2, 1);
1911+
pid = mingw_spawnv(prog, argv2, interpr);
19111912
if (pid >= 0) {
19121913
int status;
19131914
if (waitpid(pid, &status, 0) < 0)
@@ -1931,7 +1932,7 @@ int mingw_execv(const char *cmd, char *const *argv)
19311932
int exec_id;
19321933

19331934
exec_id = trace2_exec(cmd, (const char **)argv);
1934-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
1935+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
19351936
if (pid < 0) {
19361937
trace2_exec_result(exec_id, -1);
19371938
return -1;

0 commit comments

Comments
 (0)