Skip to content

Commit 8b3b7cf

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 36d0cfd commit 8b3b7cf

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

compat/mingw.c

+10-9
Original file line numberDiff line numberDiff line change
@@ -1856,8 +1856,8 @@ static int is_msys2_sh(const char *cmd)
18561856
}
18571857

18581858
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1859-
const char *dir,
1860-
int prepend_cmd, int fhin, int fhout, int fherr)
1859+
const char *dir, const char *prepend_cmd,
1860+
int fhin, int fhout, int fherr)
18611861
{
18621862
static int restrict_handle_inheritance = -1;
18631863
STARTUPINFOEXW si;
@@ -1948,9 +1948,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
19481948
/* concatenate argv, quoting args as we go */
19491949
strbuf_init(&args, 0);
19501950
if (prepend_cmd) {
1951-
char *quoted = (char *)quote_arg(cmd);
1951+
char *quoted = (char *)quote_arg(prepend_cmd);
19521952
strbuf_addstr(&args, quoted);
1953-
if (quoted != cmd)
1953+
if (quoted != prepend_cmd)
19541954
free(quoted);
19551955
}
19561956
for (; *argv; argv++) {
@@ -2109,7 +2109,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
21092109
return (pid_t)pi.dwProcessId;
21102110
}
21112111

2112-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2112+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2113+
const char *prepend_cmd)
21132114
{
21142115
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
21152116
}
@@ -2137,14 +2138,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
21372138
pid = -1;
21382139
}
21392140
else {
2140-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2141+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
21412142
fhin, fhout, fherr);
21422143
free(iprog);
21432144
}
21442145
argv[0] = argv0;
21452146
}
21462147
else
2147-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2148+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
21482149
fhin, fhout, fherr);
21492150
free(prog);
21502151
}
@@ -2172,7 +2173,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
21722173
argv2[0] = (char *)cmd; /* full path to the script file */
21732174
COPY_ARRAY(&argv2[1], &argv[1], argc);
21742175
exec_id = trace2_exec(prog, argv2);
2175-
pid = mingw_spawnv(prog, argv2, 1);
2176+
pid = mingw_spawnv(prog, argv2, interpr);
21762177
if (pid >= 0) {
21772178
int status;
21782179
if (waitpid(pid, &status, 0) < 0)
@@ -2196,7 +2197,7 @@ int mingw_execv(const char *cmd, char *const *argv)
21962197
int exec_id;
21972198

21982199
exec_id = trace2_exec(cmd, (const char **)argv);
2199-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2200+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
22002201
if (pid < 0) {
22012202
trace2_exec_result(exec_id, -1);
22022203
return -1;

0 commit comments

Comments
 (0)