Skip to content

Commit 77e6c71

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 e4b438a commit 77e6c71

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
@@ -1788,8 +1788,8 @@ static int is_msys2_sh(const char *cmd)
17881788
}
17891789

17901790
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1791-
const char *dir,
1792-
int prepend_cmd, int fhin, int fhout, int fherr)
1791+
const char *dir, const char *prepend_cmd,
1792+
int fhin, int fhout, int fherr)
17931793
{
17941794
static int restrict_handle_inheritance = -1;
17951795
STARTUPINFOEXW si;
@@ -1880,9 +1880,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
18801880
/* concatenate argv, quoting args as we go */
18811881
strbuf_init(&args, 0);
18821882
if (prepend_cmd) {
1883-
char *quoted = (char *)quote_arg(cmd);
1883+
char *quoted = (char *)quote_arg(prepend_cmd);
18841884
strbuf_addstr(&args, quoted);
1885-
if (quoted != cmd)
1885+
if (quoted != prepend_cmd)
18861886
free(quoted);
18871887
}
18881888
for (; *argv; argv++) {
@@ -2041,7 +2041,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
20412041
return (pid_t)pi.dwProcessId;
20422042
}
20432043

2044-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2044+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2045+
const char *prepend_cmd)
20452046
{
20462047
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
20472048
}
@@ -2069,14 +2070,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
20692070
pid = -1;
20702071
}
20712072
else {
2072-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2073+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
20732074
fhin, fhout, fherr);
20742075
free(iprog);
20752076
}
20762077
argv[0] = argv0;
20772078
}
20782079
else
2079-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2080+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
20802081
fhin, fhout, fherr);
20812082
free(prog);
20822083
}
@@ -2104,7 +2105,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
21042105
argv2[0] = (char *)cmd; /* full path to the script file */
21052106
COPY_ARRAY(&argv2[1], &argv[1], argc);
21062107
exec_id = trace2_exec(prog, argv2);
2107-
pid = mingw_spawnv(prog, argv2, 1);
2108+
pid = mingw_spawnv(prog, argv2, interpr);
21082109
if (pid >= 0) {
21092110
int status;
21102111
if (waitpid(pid, &status, 0) < 0)
@@ -2128,7 +2129,7 @@ int mingw_execv(const char *cmd, char *const *argv)
21282129
int exec_id;
21292130

21302131
exec_id = trace2_exec(cmd, (const char **)argv);
2131-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2132+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
21322133
if (pid < 0) {
21332134
trace2_exec_result(exec_id, -1);
21342135
return -1;

0 commit comments

Comments
 (0)