Skip to content

Commit f7645c1

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 e8b98fa commit f7645c1

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
@@ -1967,8 +1967,8 @@ static int is_msys2_sh(const char *cmd)
19671967
}
19681968

19691969
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1970-
const char *dir,
1971-
int prepend_cmd, int fhin, int fhout, int fherr)
1970+
const char *dir, const char *prepend_cmd,
1971+
int fhin, int fhout, int fherr)
19721972
{
19731973
STARTUPINFOEXW si;
19741974
PROCESS_INFORMATION pi;
@@ -2048,9 +2048,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
20482048
/* concatenate argv, quoting args as we go */
20492049
strbuf_init(&args, 0);
20502050
if (prepend_cmd) {
2051-
char *quoted = (char *)quote_arg(cmd);
2051+
char *quoted = (char *)quote_arg(prepend_cmd);
20522052
strbuf_addstr(&args, quoted);
2053-
if (quoted != cmd)
2053+
if (quoted != prepend_cmd)
20542054
free(quoted);
20552055
}
20562056
for (; *argv; argv++) {
@@ -2170,7 +2170,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
21702170
return (pid_t)pi.dwProcessId;
21712171
}
21722172

2173-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2173+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2174+
const char *prepend_cmd)
21742175
{
21752176
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
21762177
}
@@ -2198,14 +2199,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
21982199
pid = -1;
21992200
}
22002201
else {
2201-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2202+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
22022203
fhin, fhout, fherr);
22032204
free(iprog);
22042205
}
22052206
argv[0] = argv0;
22062207
}
22072208
else
2208-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2209+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
22092210
fhin, fhout, fherr);
22102211
free(prog);
22112212
}
@@ -2230,7 +2231,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
22302231
argv2[0] = (char *)cmd; /* full path to the script file */
22312232
COPY_ARRAY(&argv2[1], &argv[1], argc);
22322233
exec_id = trace2_exec(prog, (const char **)argv2);
2233-
pid = mingw_spawnv(prog, (const char **)argv2, 1);
2234+
pid = mingw_spawnv(prog, (const char **)argv2, interpr);
22342235
if (pid >= 0) {
22352236
int status;
22362237
if (waitpid(pid, &status, 0) < 0)
@@ -2254,7 +2255,7 @@ int mingw_execv(const char *cmd, char *const *argv)
22542255
int exec_id;
22552256

22562257
exec_id = trace2_exec(cmd, (const char **)argv);
2257-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2258+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
22582259
if (pid < 0) {
22592260
trace2_exec_result(exec_id, -1);
22602261
return -1;

0 commit comments

Comments
 (0)