Skip to content

Commit 71bfc44

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 d5f594e commit 71bfc44

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
@@ -1841,8 +1841,8 @@ static int is_msys2_sh(const char *cmd)
18411841
}
18421842

18431843
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1844-
const char *dir,
1845-
int prepend_cmd, int fhin, int fhout, int fherr)
1844+
const char *dir, const char *prepend_cmd,
1845+
int fhin, int fhout, int fherr)
18461846
{
18471847
static int restrict_handle_inheritance = -1;
18481848
STARTUPINFOEXW si;
@@ -1933,9 +1933,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
19331933
/* concatenate argv, quoting args as we go */
19341934
strbuf_init(&args, 0);
19351935
if (prepend_cmd) {
1936-
char *quoted = (char *)quote_arg(cmd);
1936+
char *quoted = (char *)quote_arg(prepend_cmd);
19371937
strbuf_addstr(&args, quoted);
1938-
if (quoted != cmd)
1938+
if (quoted != prepend_cmd)
19391939
free(quoted);
19401940
}
19411941
for (; *argv; argv++) {
@@ -2094,7 +2094,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
20942094
return (pid_t)pi.dwProcessId;
20952095
}
20962096

2097-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2097+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2098+
const char *prepend_cmd)
20982099
{
20992100
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
21002101
}
@@ -2122,14 +2123,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
21222123
pid = -1;
21232124
}
21242125
else {
2125-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2126+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
21262127
fhin, fhout, fherr);
21272128
free(iprog);
21282129
}
21292130
argv[0] = argv0;
21302131
}
21312132
else
2132-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2133+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
21332134
fhin, fhout, fherr);
21342135
free(prog);
21352136
}
@@ -2157,7 +2158,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
21572158
argv2[0] = (char *)cmd; /* full path to the script file */
21582159
COPY_ARRAY(&argv2[1], &argv[1], argc);
21592160
exec_id = trace2_exec(prog, argv2);
2160-
pid = mingw_spawnv(prog, argv2, 1);
2161+
pid = mingw_spawnv(prog, argv2, interpr);
21612162
if (pid >= 0) {
21622163
int status;
21632164
if (waitpid(pid, &status, 0) < 0)
@@ -2181,7 +2182,7 @@ int mingw_execv(const char *cmd, char *const *argv)
21812182
int exec_id;
21822183

21832184
exec_id = trace2_exec(cmd, (const char **)argv);
2184-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2185+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
21852186
if (pid < 0) {
21862187
trace2_exec_result(exec_id, -1);
21872188
return -1;

0 commit comments

Comments
 (0)