Skip to content

Commit bed13a7

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 706a2bf commit bed13a7

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
@@ -1882,8 +1882,8 @@ static int is_msys2_sh(const char *cmd)
18821882
}
18831883

18841884
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1885-
const char *dir,
1886-
int prepend_cmd, int fhin, int fhout, int fherr)
1885+
const char *dir, const char *prepend_cmd,
1886+
int fhin, int fhout, int fherr)
18871887
{
18881888
static int restrict_handle_inheritance = -1;
18891889
STARTUPINFOEXW si;
@@ -1974,9 +1974,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
19741974
/* concatenate argv, quoting args as we go */
19751975
strbuf_init(&args, 0);
19761976
if (prepend_cmd) {
1977-
char *quoted = (char *)quote_arg(cmd);
1977+
char *quoted = (char *)quote_arg(prepend_cmd);
19781978
strbuf_addstr(&args, quoted);
1979-
if (quoted != cmd)
1979+
if (quoted != prepend_cmd)
19801980
free(quoted);
19811981
}
19821982
for (; *argv; argv++) {
@@ -2135,7 +2135,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
21352135
return (pid_t)pi.dwProcessId;
21362136
}
21372137

2138-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2138+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2139+
const char *prepend_cmd)
21392140
{
21402141
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
21412142
}
@@ -2163,14 +2164,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
21632164
pid = -1;
21642165
}
21652166
else {
2166-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2167+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
21672168
fhin, fhout, fherr);
21682169
free(iprog);
21692170
}
21702171
argv[0] = argv0;
21712172
}
21722173
else
2173-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2174+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
21742175
fhin, fhout, fherr);
21752176
free(prog);
21762177
}
@@ -2195,7 +2196,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
21952196
argv2[0] = (char *)cmd; /* full path to the script file */
21962197
COPY_ARRAY(&argv2[1], &argv[1], argc);
21972198
exec_id = trace2_exec(prog, (const char **)argv2);
2198-
pid = mingw_spawnv(prog, (const char **)argv2, 1);
2199+
pid = mingw_spawnv(prog, (const char **)argv2, interpr);
21992200
if (pid >= 0) {
22002201
int status;
22012202
if (waitpid(pid, &status, 0) < 0)
@@ -2219,7 +2220,7 @@ int mingw_execv(const char *cmd, char *const *argv)
22192220
int exec_id;
22202221

22212222
exec_id = trace2_exec(cmd, (const char **)argv);
2222-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2223+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
22232224
if (pid < 0) {
22242225
trace2_exec_result(exec_id, -1);
22252226
return -1;

0 commit comments

Comments
 (0)