Skip to content

Commit a949e30

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 aa25a0b commit a949e30

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
@@ -1763,8 +1763,8 @@ static int is_msys2_sh(const char *cmd)
17631763
}
17641764

17651765
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1766-
const char *dir,
1767-
int prepend_cmd, int fhin, int fhout, int fherr)
1766+
const char *dir, const char *prepend_cmd,
1767+
int fhin, int fhout, int fherr)
17681768
{
17691769
static int restrict_handle_inheritance = -1;
17701770
STARTUPINFOEXW si;
@@ -1855,9 +1855,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
18551855
/* concatenate argv, quoting args as we go */
18561856
strbuf_init(&args, 0);
18571857
if (prepend_cmd) {
1858-
char *quoted = (char *)quote_arg(cmd);
1858+
char *quoted = (char *)quote_arg(prepend_cmd);
18591859
strbuf_addstr(&args, quoted);
1860-
if (quoted != cmd)
1860+
if (quoted != prepend_cmd)
18611861
free(quoted);
18621862
}
18631863
for (; *argv; argv++) {
@@ -2016,7 +2016,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
20162016
return (pid_t)pi.dwProcessId;
20172017
}
20182018

2019-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2019+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2020+
const char *prepend_cmd)
20202021
{
20212022
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
20222023
}
@@ -2044,14 +2045,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
20442045
pid = -1;
20452046
}
20462047
else {
2047-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2048+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
20482049
fhin, fhout, fherr);
20492050
free(iprog);
20502051
}
20512052
argv[0] = argv0;
20522053
}
20532054
else
2054-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2055+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
20552056
fhin, fhout, fherr);
20562057
free(prog);
20572058
}
@@ -2079,7 +2080,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
20792080
argv2[0] = (char *)cmd; /* full path to the script file */
20802081
COPY_ARRAY(&argv2[1], &argv[1], argc);
20812082
exec_id = trace2_exec(prog, argv2);
2082-
pid = mingw_spawnv(prog, argv2, 1);
2083+
pid = mingw_spawnv(prog, argv2, interpr);
20832084
if (pid >= 0) {
20842085
int status;
20852086
if (waitpid(pid, &status, 0) < 0)
@@ -2103,7 +2104,7 @@ int mingw_execv(const char *cmd, char *const *argv)
21032104
int exec_id;
21042105

21052106
exec_id = trace2_exec(cmd, (const char **)argv);
2106-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2107+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
21072108
if (pid < 0) {
21082109
trace2_exec_result(exec_id, -1);
21092110
return -1;

0 commit comments

Comments
 (0)