Skip to content

Commit 0164f9e

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 9deafeb commit 0164f9e

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

17991799
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1800-
const char *dir,
1801-
int prepend_cmd, int fhin, int fhout, int fherr)
1800+
const char *dir, const char *prepend_cmd,
1801+
int fhin, int fhout, int fherr)
18021802
{
18031803
static int restrict_handle_inheritance = -1;
18041804
STARTUPINFOEXW si;
@@ -1889,9 +1889,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
18891889
/* concatenate argv, quoting args as we go */
18901890
strbuf_init(&args, 0);
18911891
if (prepend_cmd) {
1892-
char *quoted = (char *)quote_arg(cmd);
1892+
char *quoted = (char *)quote_arg(prepend_cmd);
18931893
strbuf_addstr(&args, quoted);
1894-
if (quoted != cmd)
1894+
if (quoted != prepend_cmd)
18951895
free(quoted);
18961896
}
18971897
for (; *argv; argv++) {
@@ -2050,7 +2050,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
20502050
return (pid_t)pi.dwProcessId;
20512051
}
20522052

2053-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2053+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2054+
const char *prepend_cmd)
20542055
{
20552056
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
20562057
}
@@ -2078,14 +2079,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
20782079
pid = -1;
20792080
}
20802081
else {
2081-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2082+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
20822083
fhin, fhout, fherr);
20832084
free(iprog);
20842085
}
20852086
argv[0] = argv0;
20862087
}
20872088
else
2088-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2089+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
20892090
fhin, fhout, fherr);
20902091
free(prog);
20912092
}
@@ -2113,7 +2114,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
21132114
argv2[0] = (char *)cmd; /* full path to the script file */
21142115
COPY_ARRAY(&argv2[1], &argv[1], argc);
21152116
exec_id = trace2_exec(prog, argv2);
2116-
pid = mingw_spawnv(prog, argv2, 1);
2117+
pid = mingw_spawnv(prog, argv2, interpr);
21172118
if (pid >= 0) {
21182119
int status;
21192120
if (waitpid(pid, &status, 0) < 0)
@@ -2137,7 +2138,7 @@ int mingw_execv(const char *cmd, char *const *argv)
21372138
int exec_id;
21382139

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

0 commit comments

Comments
 (0)