Skip to content

Commit d95bb77

Browse files
dschovdye
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 1db8af5 commit d95bb77

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
@@ -1811,8 +1811,8 @@ static int is_msys2_sh(const char *cmd)
18111811
}
18121812

18131813
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1814-
const char *dir,
1815-
int prepend_cmd, int fhin, int fhout, int fherr)
1814+
const char *dir, const char *prepend_cmd,
1815+
int fhin, int fhout, int fherr)
18161816
{
18171817
static int restrict_handle_inheritance = -1;
18181818
STARTUPINFOEXW si;
@@ -1903,9 +1903,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
19031903
/* concatenate argv, quoting args as we go */
19041904
strbuf_init(&args, 0);
19051905
if (prepend_cmd) {
1906-
char *quoted = (char *)quote_arg(cmd);
1906+
char *quoted = (char *)quote_arg(prepend_cmd);
19071907
strbuf_addstr(&args, quoted);
1908-
if (quoted != cmd)
1908+
if (quoted != prepend_cmd)
19091909
free(quoted);
19101910
}
19111911
for (; *argv; argv++) {
@@ -2064,7 +2064,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
20642064
return (pid_t)pi.dwProcessId;
20652065
}
20662066

2067-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2067+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2068+
const char *prepend_cmd)
20682069
{
20692070
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
20702071
}
@@ -2092,14 +2093,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
20922093
pid = -1;
20932094
}
20942095
else {
2095-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2096+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
20962097
fhin, fhout, fherr);
20972098
free(iprog);
20982099
}
20992100
argv[0] = argv0;
21002101
}
21012102
else
2102-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2103+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
21032104
fhin, fhout, fherr);
21042105
free(prog);
21052106
}
@@ -2127,7 +2128,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
21272128
argv2[0] = (char *)cmd; /* full path to the script file */
21282129
COPY_ARRAY(&argv2[1], &argv[1], argc);
21292130
exec_id = trace2_exec(prog, argv2);
2130-
pid = mingw_spawnv(prog, argv2, 1);
2131+
pid = mingw_spawnv(prog, argv2, interpr);
21312132
if (pid >= 0) {
21322133
int status;
21332134
if (waitpid(pid, &status, 0) < 0)
@@ -2151,7 +2152,7 @@ int mingw_execv(const char *cmd, char *const *argv)
21512152
int exec_id;
21522153

21532154
exec_id = trace2_exec(cmd, (const char **)argv);
2154-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2155+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
21552156
if (pid < 0) {
21562157
trace2_exec_result(exec_id, -1);
21572158
return -1;

0 commit comments

Comments
 (0)