Skip to content

Commit 76340bc

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 a2f18f9 commit 76340bc

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
@@ -1965,8 +1965,8 @@ static int is_msys2_sh(const char *cmd)
19651965
}
19661966

19671967
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1968-
const char *dir,
1969-
int prepend_cmd, int fhin, int fhout, int fherr)
1968+
const char *dir, const char *prepend_cmd,
1969+
int fhin, int fhout, int fherr)
19701970
{
19711971
static int restrict_handle_inheritance = -1;
19721972
STARTUPINFOEXW si;
@@ -2057,9 +2057,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
20572057
/* concatenate argv, quoting args as we go */
20582058
strbuf_init(&args, 0);
20592059
if (prepend_cmd) {
2060-
char *quoted = (char *)quote_arg(cmd);
2060+
char *quoted = (char *)quote_arg(prepend_cmd);
20612061
strbuf_addstr(&args, quoted);
2062-
if (quoted != cmd)
2062+
if (quoted != prepend_cmd)
20632063
free(quoted);
20642064
}
20652065
for (; *argv; argv++) {
@@ -2218,7 +2218,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
22182218
return (pid_t)pi.dwProcessId;
22192219
}
22202220

2221-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2221+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2222+
const char *prepend_cmd)
22222223
{
22232224
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
22242225
}
@@ -2246,14 +2247,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
22462247
pid = -1;
22472248
}
22482249
else {
2249-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2250+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
22502251
fhin, fhout, fherr);
22512252
free(iprog);
22522253
}
22532254
argv[0] = argv0;
22542255
}
22552256
else
2256-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2257+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
22572258
fhin, fhout, fherr);
22582259
free(prog);
22592260
}
@@ -2278,7 +2279,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
22782279
argv2[0] = (char *)cmd; /* full path to the script file */
22792280
COPY_ARRAY(&argv2[1], &argv[1], argc);
22802281
exec_id = trace2_exec(prog, (const char **)argv2);
2281-
pid = mingw_spawnv(prog, (const char **)argv2, 1);
2282+
pid = mingw_spawnv(prog, (const char **)argv2, interpr);
22822283
if (pid >= 0) {
22832284
int status;
22842285
if (waitpid(pid, &status, 0) < 0)
@@ -2302,7 +2303,7 @@ int mingw_execv(const char *cmd, char *const *argv)
23022303
int exec_id;
23032304

23042305
exec_id = trace2_exec(cmd, (const char **)argv);
2305-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2306+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
23062307
if (pid < 0) {
23072308
trace2_exec_result(exec_id, -1);
23082309
return -1;

0 commit comments

Comments
 (0)