Skip to content

Commit 8f65fdf

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 07167b3 commit 8f65fdf

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

18141814
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1815-
const char *dir,
1816-
int prepend_cmd, int fhin, int fhout, int fherr)
1815+
const char *dir, const char *prepend_cmd,
1816+
int fhin, int fhout, int fherr)
18171817
{
18181818
static int restrict_handle_inheritance = -1;
18191819
STARTUPINFOEXW si;
@@ -1904,9 +1904,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
19041904
/* concatenate argv, quoting args as we go */
19051905
strbuf_init(&args, 0);
19061906
if (prepend_cmd) {
1907-
char *quoted = (char *)quote_arg(cmd);
1907+
char *quoted = (char *)quote_arg(prepend_cmd);
19081908
strbuf_addstr(&args, quoted);
1909-
if (quoted != cmd)
1909+
if (quoted != prepend_cmd)
19101910
free(quoted);
19111911
}
19121912
for (; *argv; argv++) {
@@ -2065,7 +2065,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
20652065
return (pid_t)pi.dwProcessId;
20662066
}
20672067

2068-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2068+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2069+
const char *prepend_cmd)
20692070
{
20702071
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
20712072
}
@@ -2093,14 +2094,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
20932094
pid = -1;
20942095
}
20952096
else {
2096-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2097+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
20972098
fhin, fhout, fherr);
20982099
free(iprog);
20992100
}
21002101
argv[0] = argv0;
21012102
}
21022103
else
2103-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2104+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
21042105
fhin, fhout, fherr);
21052106
free(prog);
21062107
}
@@ -2128,7 +2129,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
21282129
argv2[0] = (char *)cmd; /* full path to the script file */
21292130
COPY_ARRAY(&argv2[1], &argv[1], argc);
21302131
exec_id = trace2_exec(prog, argv2);
2131-
pid = mingw_spawnv(prog, argv2, 1);
2132+
pid = mingw_spawnv(prog, argv2, interpr);
21322133
if (pid >= 0) {
21332134
int status;
21342135
if (waitpid(pid, &status, 0) < 0)
@@ -2152,7 +2153,7 @@ int mingw_execv(const char *cmd, char *const *argv)
21522153
int exec_id;
21532154

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

0 commit comments

Comments
 (0)