Skip to content

Commit 8df24b7

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 1c7a8c5 commit 8df24b7

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
@@ -1868,8 +1868,8 @@ static int is_msys2_sh(const char *cmd)
18681868
}
18691869

18701870
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1871-
const char *dir,
1872-
int prepend_cmd, int fhin, int fhout, int fherr)
1871+
const char *dir, const char *prepend_cmd,
1872+
int fhin, int fhout, int fherr)
18731873
{
18741874
static int restrict_handle_inheritance = -1;
18751875
STARTUPINFOEXW si;
@@ -1960,9 +1960,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
19601960
/* concatenate argv, quoting args as we go */
19611961
strbuf_init(&args, 0);
19621962
if (prepend_cmd) {
1963-
char *quoted = (char *)quote_arg(cmd);
1963+
char *quoted = (char *)quote_arg(prepend_cmd);
19641964
strbuf_addstr(&args, quoted);
1965-
if (quoted != cmd)
1965+
if (quoted != prepend_cmd)
19661966
free(quoted);
19671967
}
19681968
for (; *argv; argv++) {
@@ -2121,7 +2121,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
21212121
return (pid_t)pi.dwProcessId;
21222122
}
21232123

2124-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2124+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2125+
const char *prepend_cmd)
21252126
{
21262127
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
21272128
}
@@ -2149,14 +2150,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
21492150
pid = -1;
21502151
}
21512152
else {
2152-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2153+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
21532154
fhin, fhout, fherr);
21542155
free(iprog);
21552156
}
21562157
argv[0] = argv0;
21572158
}
21582159
else
2159-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2160+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
21602161
fhin, fhout, fherr);
21612162
free(prog);
21622163
}
@@ -2181,7 +2182,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
21812182
argv2[0] = (char *)cmd; /* full path to the script file */
21822183
COPY_ARRAY(&argv2[1], &argv[1], argc);
21832184
exec_id = trace2_exec(prog, (const char **)argv2);
2184-
pid = mingw_spawnv(prog, (const char **)argv2, 1);
2185+
pid = mingw_spawnv(prog, (const char **)argv2, interpr);
21852186
if (pid >= 0) {
21862187
int status;
21872188
if (waitpid(pid, &status, 0) < 0)
@@ -2205,7 +2206,7 @@ int mingw_execv(const char *cmd, char *const *argv)
22052206
int exec_id;
22062207

22072208
exec_id = trace2_exec(cmd, (const char **)argv);
2208-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2209+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
22092210
if (pid < 0) {
22102211
trace2_exec_result(exec_id, -1);
22112212
return -1;

0 commit comments

Comments
 (0)