Skip to content

Commit 08dde17

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 b4744d8 commit 08dde17

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
@@ -1898,8 +1898,8 @@ static int is_msys2_sh(const char *cmd)
18981898
}
18991899

19001900
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1901-
const char *dir,
1902-
int prepend_cmd, int fhin, int fhout, int fherr)
1901+
const char *dir, const char *prepend_cmd,
1902+
int fhin, int fhout, int fherr)
19031903
{
19041904
static int restrict_handle_inheritance = -1;
19051905
STARTUPINFOEXW si;
@@ -1990,9 +1990,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
19901990
/* concatenate argv, quoting args as we go */
19911991
strbuf_init(&args, 0);
19921992
if (prepend_cmd) {
1993-
char *quoted = (char *)quote_arg(cmd);
1993+
char *quoted = (char *)quote_arg(prepend_cmd);
19941994
strbuf_addstr(&args, quoted);
1995-
if (quoted != cmd)
1995+
if (quoted != prepend_cmd)
19961996
free(quoted);
19971997
}
19981998
for (; *argv; argv++) {
@@ -2151,7 +2151,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
21512151
return (pid_t)pi.dwProcessId;
21522152
}
21532153

2154-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2154+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2155+
const char *prepend_cmd)
21552156
{
21562157
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
21572158
}
@@ -2179,14 +2180,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
21792180
pid = -1;
21802181
}
21812182
else {
2182-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2183+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
21832184
fhin, fhout, fherr);
21842185
free(iprog);
21852186
}
21862187
argv[0] = argv0;
21872188
}
21882189
else
2189-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2190+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
21902191
fhin, fhout, fherr);
21912192
free(prog);
21922193
}
@@ -2211,7 +2212,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
22112212
argv2[0] = (char *)cmd; /* full path to the script file */
22122213
COPY_ARRAY(&argv2[1], &argv[1], argc);
22132214
exec_id = trace2_exec(prog, (const char **)argv2);
2214-
pid = mingw_spawnv(prog, (const char **)argv2, 1);
2215+
pid = mingw_spawnv(prog, (const char **)argv2, interpr);
22152216
if (pid >= 0) {
22162217
int status;
22172218
if (waitpid(pid, &status, 0) < 0)
@@ -2235,7 +2236,7 @@ int mingw_execv(const char *cmd, char *const *argv)
22352236
int exec_id;
22362237

22372238
exec_id = trace2_exec(cmd, (const char **)argv);
2238-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2239+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
22392240
if (pid < 0) {
22402241
trace2_exec_result(exec_id, -1);
22412242
return -1;

0 commit comments

Comments
 (0)