Skip to content

Commit 4df645b

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 f343388 commit 4df645b

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
@@ -1630,8 +1630,8 @@ static int is_msys2_sh(const char *cmd)
16301630
}
16311631

16321632
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1633-
const char *dir,
1634-
int prepend_cmd, int fhin, int fhout, int fherr)
1633+
const char *dir, const char *prepend_cmd,
1634+
int fhin, int fhout, int fherr)
16351635
{
16361636
static int restrict_handle_inheritance = -1;
16371637
STARTUPINFOEXW si;
@@ -1718,9 +1718,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
17181718
/* concatenate argv, quoting args as we go */
17191719
strbuf_init(&args, 0);
17201720
if (prepend_cmd) {
1721-
char *quoted = (char *)quote_arg(cmd);
1721+
char *quoted = (char *)quote_arg(prepend_cmd);
17221722
strbuf_addstr(&args, quoted);
1723-
if (quoted != cmd)
1723+
if (quoted != prepend_cmd)
17241724
free(quoted);
17251725
}
17261726
for (; *argv; argv++) {
@@ -1878,7 +1878,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
18781878
return (pid_t)pi.dwProcessId;
18791879
}
18801880

1881-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
1881+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
1882+
const char *prepend_cmd)
18821883
{
18831884
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
18841885
}
@@ -1906,14 +1907,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
19061907
pid = -1;
19071908
}
19081909
else {
1909-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
1910+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
19101911
fhin, fhout, fherr);
19111912
free(iprog);
19121913
}
19131914
argv[0] = argv0;
19141915
}
19151916
else
1916-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
1917+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
19171918
fhin, fhout, fherr);
19181919
free(prog);
19191920
}
@@ -1941,7 +1942,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
19411942
argv2[0] = (char *)cmd; /* full path to the script file */
19421943
memcpy(&argv2[1], &argv[1], sizeof(*argv) * argc);
19431944
exec_id = trace2_exec(prog, argv2);
1944-
pid = mingw_spawnv(prog, argv2, 1);
1945+
pid = mingw_spawnv(prog, argv2, interpr);
19451946
if (pid >= 0) {
19461947
int status;
19471948
if (waitpid(pid, &status, 0) < 0)
@@ -1965,7 +1966,7 @@ int mingw_execv(const char *cmd, char *const *argv)
19651966
int exec_id;
19661967

19671968
exec_id = trace2_exec(cmd, (const char **)argv);
1968-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
1969+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
19691970
if (pid < 0) {
19701971
trace2_exec_result(exec_id, -1);
19711972
return -1;

0 commit comments

Comments
 (0)