Skip to content

Commit 434e77e

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 4fe68fc commit 434e77e

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
@@ -1796,8 +1796,8 @@ static int is_msys2_sh(const char *cmd)
17961796
}
17971797

17981798
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1799-
const char *dir,
1800-
int prepend_cmd, int fhin, int fhout, int fherr)
1799+
const char *dir, const char *prepend_cmd,
1800+
int fhin, int fhout, int fherr)
18011801
{
18021802
static int restrict_handle_inheritance = -1;
18031803
STARTUPINFOEXW si;
@@ -1888,9 +1888,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
18881888
/* concatenate argv, quoting args as we go */
18891889
strbuf_init(&args, 0);
18901890
if (prepend_cmd) {
1891-
char *quoted = (char *)quote_arg(cmd);
1891+
char *quoted = (char *)quote_arg(prepend_cmd);
18921892
strbuf_addstr(&args, quoted);
1893-
if (quoted != cmd)
1893+
if (quoted != prepend_cmd)
18941894
free(quoted);
18951895
}
18961896
for (; *argv; argv++) {
@@ -2049,7 +2049,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
20492049
return (pid_t)pi.dwProcessId;
20502050
}
20512051

2052-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2052+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2053+
const char *prepend_cmd)
20532054
{
20542055
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
20552056
}
@@ -2077,14 +2078,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
20772078
pid = -1;
20782079
}
20792080
else {
2080-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2081+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
20812082
fhin, fhout, fherr);
20822083
free(iprog);
20832084
}
20842085
argv[0] = argv0;
20852086
}
20862087
else
2087-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2088+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
20882089
fhin, fhout, fherr);
20892090
free(prog);
20902091
}
@@ -2112,7 +2113,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
21122113
argv2[0] = (char *)cmd; /* full path to the script file */
21132114
COPY_ARRAY(&argv2[1], &argv[1], argc);
21142115
exec_id = trace2_exec(prog, argv2);
2115-
pid = mingw_spawnv(prog, argv2, 1);
2116+
pid = mingw_spawnv(prog, argv2, interpr);
21162117
if (pid >= 0) {
21172118
int status;
21182119
if (waitpid(pid, &status, 0) < 0)
@@ -2136,7 +2137,7 @@ int mingw_execv(const char *cmd, char *const *argv)
21362137
int exec_id;
21372138

21382139
exec_id = trace2_exec(cmd, (const char **)argv);
2139-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2140+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
21402141
if (pid < 0) {
21412142
trace2_exec_result(exec_id, -1);
21422143
return -1;

0 commit comments

Comments
 (0)