Skip to content

Commit acb4a2f

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 3ce396f commit acb4a2f

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
@@ -1992,8 +1992,8 @@ static int is_msys2_sh(const char *cmd)
19921992
}
19931993

19941994
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1995-
const char *dir,
1996-
int prepend_cmd, int fhin, int fhout, int fherr)
1995+
const char *dir, const char *prepend_cmd,
1996+
int fhin, int fhout, int fherr)
19971997
{
19981998
STARTUPINFOEXW si;
19991999
PROCESS_INFORMATION pi;
@@ -2073,9 +2073,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
20732073
/* concatenate argv, quoting args as we go */
20742074
strbuf_init(&args, 0);
20752075
if (prepend_cmd) {
2076-
char *quoted = (char *)quote_arg(cmd);
2076+
char *quoted = (char *)quote_arg(prepend_cmd);
20772077
strbuf_addstr(&args, quoted);
2078-
if (quoted != cmd)
2078+
if (quoted != prepend_cmd)
20792079
free(quoted);
20802080
}
20812081
for (; *argv; argv++) {
@@ -2195,7 +2195,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
21952195
return (pid_t)pi.dwProcessId;
21962196
}
21972197

2198-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2198+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2199+
const char *prepend_cmd)
21992200
{
22002201
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
22012202
}
@@ -2223,14 +2224,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
22232224
pid = -1;
22242225
}
22252226
else {
2226-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2227+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
22272228
fhin, fhout, fherr);
22282229
free(iprog);
22292230
}
22302231
argv[0] = argv0;
22312232
}
22322233
else
2233-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2234+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
22342235
fhin, fhout, fherr);
22352236
free(prog);
22362237
}
@@ -2255,7 +2256,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
22552256
argv2[0] = (char *)cmd; /* full path to the script file */
22562257
COPY_ARRAY(&argv2[1], &argv[1], argc);
22572258
exec_id = trace2_exec(prog, (const char **)argv2);
2258-
pid = mingw_spawnv(prog, (const char **)argv2, 1);
2259+
pid = mingw_spawnv(prog, (const char **)argv2, interpr);
22592260
if (pid >= 0) {
22602261
int status;
22612262
if (waitpid(pid, &status, 0) < 0)
@@ -2279,7 +2280,7 @@ int mingw_execv(const char *cmd, char *const *argv)
22792280
int exec_id;
22802281

22812282
exec_id = trace2_exec(cmd, (const char **)argv);
2282-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2283+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
22832284
if (pid < 0) {
22842285
trace2_exec_result(exec_id, -1);
22852286
return -1;

0 commit comments

Comments
 (0)