Skip to content

Commit 218fecd

Browse files
dschoGit for Windows Build Agent
authored andcommitted
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 <johannes.schindelin@gmx.de>
1 parent 50ea91a commit 218fecd

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

compat/mingw.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,8 +2073,8 @@ static int is_msys2_sh(const char *cmd)
20732073
}
20742074

20752075
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
2076-
const char *dir,
2077-
int prepend_cmd, int fhin, int fhout, int fherr)
2076+
const char *dir, const char *prepend_cmd,
2077+
int fhin, int fhout, int fherr)
20782078
{
20792079
STARTUPINFOEXW si;
20802080
PROCESS_INFORMATION pi;
@@ -2154,9 +2154,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
21542154
/* concatenate argv, quoting args as we go */
21552155
strbuf_init(&args, 0);
21562156
if (prepend_cmd) {
2157-
char *quoted = (char *)quote_arg(cmd);
2157+
char *quoted = (char *)quote_arg(prepend_cmd);
21582158
strbuf_addstr(&args, quoted);
2159-
if (quoted != cmd)
2159+
if (quoted != prepend_cmd)
21602160
free(quoted);
21612161
}
21622162
for (; *argv; argv++) {
@@ -2276,7 +2276,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
22762276
return (pid_t)pi.dwProcessId;
22772277
}
22782278

2279-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2279+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2280+
const char *prepend_cmd)
22802281
{
22812282
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
22822283
}
@@ -2304,14 +2305,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
23042305
pid = -1;
23052306
}
23062307
else {
2307-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2308+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
23082309
fhin, fhout, fherr);
23092310
free(iprog);
23102311
}
23112312
argv[0] = argv0;
23122313
}
23132314
else
2314-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2315+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
23152316
fhin, fhout, fherr);
23162317
free(prog);
23172318
}
@@ -2336,7 +2337,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
23362337
argv2[0] = (char *)cmd; /* full path to the script file */
23372338
COPY_ARRAY(&argv2[1], &argv[1], argc);
23382339
exec_id = trace2_exec(prog, (const char **)argv2);
2339-
pid = mingw_spawnv(prog, (const char **)argv2, 1);
2340+
pid = mingw_spawnv(prog, (const char **)argv2, interpr);
23402341
if (pid >= 0) {
23412342
int status;
23422343
if (waitpid(pid, &status, 0) < 0)
@@ -2360,7 +2361,7 @@ int mingw_execv(const char *cmd, char *const *argv)
23602361
int exec_id;
23612362

23622363
exec_id = trace2_exec(cmd, (const char **)argv);
2363-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2364+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
23642365
if (pid < 0) {
23652366
trace2_exec_result(exec_id, -1);
23662367
return -1;

0 commit comments

Comments
 (0)