Skip to content

Commit 72be863

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 3bc5590 commit 72be863

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
@@ -1977,8 +1977,8 @@ static int is_msys2_sh(const char *cmd)
19771977
}
19781978

19791979
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1980-
const char *dir,
1981-
int prepend_cmd, int fhin, int fhout, int fherr)
1980+
const char *dir, const char *prepend_cmd,
1981+
int fhin, int fhout, int fherr)
19821982
{
19831983
static int restrict_handle_inheritance = -1;
19841984
STARTUPINFOEXW si;
@@ -2069,9 +2069,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
20692069
/* concatenate argv, quoting args as we go */
20702070
strbuf_init(&args, 0);
20712071
if (prepend_cmd) {
2072-
char *quoted = (char *)quote_arg(cmd);
2072+
char *quoted = (char *)quote_arg(prepend_cmd);
20732073
strbuf_addstr(&args, quoted);
2074-
if (quoted != cmd)
2074+
if (quoted != prepend_cmd)
20752075
free(quoted);
20762076
}
20772077
for (; *argv; argv++) {
@@ -2230,7 +2230,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
22302230
return (pid_t)pi.dwProcessId;
22312231
}
22322232

2233-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2233+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2234+
const char *prepend_cmd)
22342235
{
22352236
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
22362237
}
@@ -2258,14 +2259,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
22582259
pid = -1;
22592260
}
22602261
else {
2261-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2262+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
22622263
fhin, fhout, fherr);
22632264
free(iprog);
22642265
}
22652266
argv[0] = argv0;
22662267
}
22672268
else
2268-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2269+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
22692270
fhin, fhout, fherr);
22702271
free(prog);
22712272
}
@@ -2290,7 +2291,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
22902291
argv2[0] = (char *)cmd; /* full path to the script file */
22912292
COPY_ARRAY(&argv2[1], &argv[1], argc);
22922293
exec_id = trace2_exec(prog, (const char **)argv2);
2293-
pid = mingw_spawnv(prog, (const char **)argv2, 1);
2294+
pid = mingw_spawnv(prog, (const char **)argv2, interpr);
22942295
if (pid >= 0) {
22952296
int status;
22962297
if (waitpid(pid, &status, 0) < 0)
@@ -2314,7 +2315,7 @@ int mingw_execv(const char *cmd, char *const *argv)
23142315
int exec_id;
23152316

23162317
exec_id = trace2_exec(cmd, (const char **)argv);
2317-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2318+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
23182319
if (pid < 0) {
23192320
trace2_exec_result(exec_id, -1);
23202321
return -1;

0 commit comments

Comments
 (0)