Skip to content

Commit f54aa1f

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 f6e2a3c commit f54aa1f

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;
@@ -1681,9 +1681,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
16811681
/* concatenate argv, quoting args as we go */
16821682
strbuf_init(&args, 0);
16831683
if (prepend_cmd) {
1684-
char *quoted = (char *)quote_arg(cmd);
1684+
char *quoted = (char *)quote_arg(prepend_cmd);
16851685
strbuf_addstr(&args, quoted);
1686-
if (quoted != cmd)
1686+
if (quoted != prepend_cmd)
16871687
free(quoted);
16881688
}
16891689
for (; *argv; argv++) {
@@ -1841,7 +1841,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
18411841
return (pid_t)pi.dwProcessId;
18421842
}
18431843

1844-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
1844+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
1845+
const char *prepend_cmd)
18451846
{
18461847
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
18471848
}
@@ -1869,14 +1870,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
18691870
pid = -1;
18701871
}
18711872
else {
1872-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
1873+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
18731874
fhin, fhout, fherr);
18741875
free(iprog);
18751876
}
18761877
argv[0] = argv0;
18771878
}
18781879
else
1879-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
1880+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
18801881
fhin, fhout, fherr);
18811882
free(prog);
18821883
}
@@ -1904,7 +1905,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
19041905
argv2[0] = (char *)cmd; /* full path to the script file */
19051906
memcpy(&argv2[1], &argv[1], sizeof(*argv) * argc);
19061907
exec_id = trace2_exec(prog, argv2);
1907-
pid = mingw_spawnv(prog, argv2, 1);
1908+
pid = mingw_spawnv(prog, argv2, interpr);
19081909
if (pid >= 0) {
19091910
int status;
19101911
if (waitpid(pid, &status, 0) < 0)
@@ -1928,7 +1929,7 @@ int mingw_execv(const char *cmd, char *const *argv)
19281929
int exec_id;
19291930

19301931
exec_id = trace2_exec(cmd, (const char **)argv);
1931-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
1932+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
19321933
if (pid < 0) {
19331934
trace2_exec_result(exec_id, -1);
19341935
return -1;

0 commit comments

Comments
 (0)