Skip to content

Commit d1916c7

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 6a95af3 commit d1916c7

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
}
@@ -1905,7 +1906,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
19051906
ALLOC_ARRAY(argv2, argc + 1);
19061907
argv2[0] = (char *)cmd; /* full path to the script file */
19071908
memcpy(&argv2[1], &argv[1], sizeof(*argv) * argc);
1908-
pid = mingw_spawnv(prog, argv2, 1);
1909+
pid = mingw_spawnv(prog, argv2, interpr);
19091910
if (pid >= 0) {
19101911
int status;
19111912
if (waitpid(pid, &status, 0) < 0)
@@ -1925,7 +1926,7 @@ int mingw_execv(const char *cmd, char *const *argv)
19251926
if (!try_shell_exec(cmd, argv)) {
19261927
int pid, status;
19271928

1928-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
1929+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
19291930
if (pid < 0)
19301931
return -1;
19311932
if (waitpid(pid, &status, 0) < 0)

0 commit comments

Comments
 (0)