Skip to content

Commit 4f8aef2

Browse files
dschomjcheetham
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 <[email protected]>
1 parent 3ebb19b commit 4f8aef2

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
@@ -1877,8 +1877,8 @@ static int is_msys2_sh(const char *cmd)
18771877
}
18781878

18791879
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1880-
const char *dir,
1881-
int prepend_cmd, int fhin, int fhout, int fherr)
1880+
const char *dir, const char *prepend_cmd,
1881+
int fhin, int fhout, int fherr)
18821882
{
18831883
static int restrict_handle_inheritance = -1;
18841884
STARTUPINFOEXW si;
@@ -1969,9 +1969,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
19691969
/* concatenate argv, quoting args as we go */
19701970
strbuf_init(&args, 0);
19711971
if (prepend_cmd) {
1972-
char *quoted = (char *)quote_arg(cmd);
1972+
char *quoted = (char *)quote_arg(prepend_cmd);
19731973
strbuf_addstr(&args, quoted);
1974-
if (quoted != cmd)
1974+
if (quoted != prepend_cmd)
19751975
free(quoted);
19761976
}
19771977
for (; *argv; argv++) {
@@ -2130,7 +2130,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
21302130
return (pid_t)pi.dwProcessId;
21312131
}
21322132

2133-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2133+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2134+
const char *prepend_cmd)
21342135
{
21352136
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
21362137
}
@@ -2158,14 +2159,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
21582159
pid = -1;
21592160
}
21602161
else {
2161-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2162+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
21622163
fhin, fhout, fherr);
21632164
free(iprog);
21642165
}
21652166
argv[0] = argv0;
21662167
}
21672168
else
2168-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2169+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
21692170
fhin, fhout, fherr);
21702171
free(prog);
21712172
}
@@ -2190,7 +2191,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
21902191
argv2[0] = (char *)cmd; /* full path to the script file */
21912192
COPY_ARRAY(&argv2[1], &argv[1], argc);
21922193
exec_id = trace2_exec(prog, (const char **)argv2);
2193-
pid = mingw_spawnv(prog, (const char **)argv2, 1);
2194+
pid = mingw_spawnv(prog, (const char **)argv2, interpr);
21942195
if (pid >= 0) {
21952196
int status;
21962197
if (waitpid(pid, &status, 0) < 0)
@@ -2214,7 +2215,7 @@ int mingw_execv(const char *cmd, char *const *argv)
22142215
int exec_id;
22152216

22162217
exec_id = trace2_exec(cmd, (const char **)argv);
2217-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2218+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
22182219
if (pid < 0) {
22192220
trace2_exec_result(exec_id, -1);
22202221
return -1;

0 commit comments

Comments
 (0)