Skip to content

Commit 06a1e74

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 ba2a48e commit 06a1e74

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
@@ -1813,8 +1813,8 @@ static int is_msys2_sh(const char *cmd)
18131813
}
18141814

18151815
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1816-
const char *dir,
1817-
int prepend_cmd, int fhin, int fhout, int fherr)
1816+
const char *dir, const char *prepend_cmd,
1817+
int fhin, int fhout, int fherr)
18181818
{
18191819
static int restrict_handle_inheritance = -1;
18201820
STARTUPINFOEXW si;
@@ -1905,9 +1905,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
19051905
/* concatenate argv, quoting args as we go */
19061906
strbuf_init(&args, 0);
19071907
if (prepend_cmd) {
1908-
char *quoted = (char *)quote_arg(cmd);
1908+
char *quoted = (char *)quote_arg(prepend_cmd);
19091909
strbuf_addstr(&args, quoted);
1910-
if (quoted != cmd)
1910+
if (quoted != prepend_cmd)
19111911
free(quoted);
19121912
}
19131913
for (; *argv; argv++) {
@@ -2066,7 +2066,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
20662066
return (pid_t)pi.dwProcessId;
20672067
}
20682068

2069-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2069+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2070+
const char *prepend_cmd)
20702071
{
20712072
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
20722073
}
@@ -2094,14 +2095,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
20942095
pid = -1;
20952096
}
20962097
else {
2097-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2098+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
20982099
fhin, fhout, fherr);
20992100
free(iprog);
21002101
}
21012102
argv[0] = argv0;
21022103
}
21032104
else
2104-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2105+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
21052106
fhin, fhout, fherr);
21062107
free(prog);
21072108
}
@@ -2129,7 +2130,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
21292130
argv2[0] = (char *)cmd; /* full path to the script file */
21302131
COPY_ARRAY(&argv2[1], &argv[1], argc);
21312132
exec_id = trace2_exec(prog, argv2);
2132-
pid = mingw_spawnv(prog, argv2, 1);
2133+
pid = mingw_spawnv(prog, argv2, interpr);
21332134
if (pid >= 0) {
21342135
int status;
21352136
if (waitpid(pid, &status, 0) < 0)
@@ -2153,7 +2154,7 @@ int mingw_execv(const char *cmd, char *const *argv)
21532154
int exec_id;
21542155

21552156
exec_id = trace2_exec(cmd, (const char **)argv);
2156-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2157+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
21572158
if (pid < 0) {
21582159
trace2_exec_result(exec_id, -1);
21592160
return -1;

0 commit comments

Comments
 (0)