Skip to content

Commit e174f19

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 c003325 commit e174f19

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
@@ -1664,8 +1664,8 @@ static int is_msys2_sh(const char *cmd)
16641664
}
16651665

16661666
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1667-
const char *dir,
1668-
int prepend_cmd, int fhin, int fhout, int fherr)
1667+
const char *dir, const char *prepend_cmd,
1668+
int fhin, int fhout, int fherr)
16691669
{
16701670
static int restrict_handle_inheritance = -1;
16711671
STARTUPINFOEXW si;
@@ -1756,9 +1756,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
17561756
/* concatenate argv, quoting args as we go */
17571757
strbuf_init(&args, 0);
17581758
if (prepend_cmd) {
1759-
char *quoted = (char *)quote_arg(cmd);
1759+
char *quoted = (char *)quote_arg(prepend_cmd);
17601760
strbuf_addstr(&args, quoted);
1761-
if (quoted != cmd)
1761+
if (quoted != prepend_cmd)
17621762
free(quoted);
17631763
}
17641764
for (; *argv; argv++) {
@@ -1917,7 +1917,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
19171917
return (pid_t)pi.dwProcessId;
19181918
}
19191919

1920-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
1920+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
1921+
const char *prepend_cmd)
19211922
{
19221923
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
19231924
}
@@ -1945,14 +1946,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
19451946
pid = -1;
19461947
}
19471948
else {
1948-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
1949+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
19491950
fhin, fhout, fherr);
19501951
free(iprog);
19511952
}
19521953
argv[0] = argv0;
19531954
}
19541955
else
1955-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
1956+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
19561957
fhin, fhout, fherr);
19571958
free(prog);
19581959
}
@@ -1980,7 +1981,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
19801981
argv2[0] = (char *)cmd; /* full path to the script file */
19811982
COPY_ARRAY(&argv2[1], &argv[1], argc);
19821983
exec_id = trace2_exec(prog, argv2);
1983-
pid = mingw_spawnv(prog, argv2, 1);
1984+
pid = mingw_spawnv(prog, argv2, interpr);
19841985
if (pid >= 0) {
19851986
int status;
19861987
if (waitpid(pid, &status, 0) < 0)
@@ -2004,7 +2005,7 @@ int mingw_execv(const char *cmd, char *const *argv)
20042005
int exec_id;
20052006

20062007
exec_id = trace2_exec(cmd, (const char **)argv);
2007-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2008+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
20082009
if (pid < 0) {
20092010
trace2_exec_result(exec_id, -1);
20102011
return -1;

0 commit comments

Comments
 (0)