Skip to content

Commit 000c982

Browse files
dschomjcheetham
authored andcommitted
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 c7b8552 commit 000c982

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
@@ -1896,8 +1896,8 @@ static int is_msys2_sh(const char *cmd)
18961896
}
18971897

18981898
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1899-
const char *dir,
1900-
int prepend_cmd, int fhin, int fhout, int fherr)
1899+
const char *dir, const char *prepend_cmd,
1900+
int fhin, int fhout, int fherr)
19011901
{
19021902
static int restrict_handle_inheritance = -1;
19031903
STARTUPINFOEXW si;
@@ -1988,9 +1988,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
19881988
/* concatenate argv, quoting args as we go */
19891989
strbuf_init(&args, 0);
19901990
if (prepend_cmd) {
1991-
char *quoted = (char *)quote_arg(cmd);
1991+
char *quoted = (char *)quote_arg(prepend_cmd);
19921992
strbuf_addstr(&args, quoted);
1993-
if (quoted != cmd)
1993+
if (quoted != prepend_cmd)
19941994
free(quoted);
19951995
}
19961996
for (; *argv; argv++) {
@@ -2149,7 +2149,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
21492149
return (pid_t)pi.dwProcessId;
21502150
}
21512151

2152-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2152+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2153+
const char *prepend_cmd)
21532154
{
21542155
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
21552156
}
@@ -2177,14 +2178,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
21772178
pid = -1;
21782179
}
21792180
else {
2180-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2181+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
21812182
fhin, fhout, fherr);
21822183
free(iprog);
21832184
}
21842185
argv[0] = argv0;
21852186
}
21862187
else
2187-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2188+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
21882189
fhin, fhout, fherr);
21892190
free(prog);
21902191
}
@@ -2209,7 +2210,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
22092210
argv2[0] = (char *)cmd; /* full path to the script file */
22102211
COPY_ARRAY(&argv2[1], &argv[1], argc);
22112212
exec_id = trace2_exec(prog, (const char **)argv2);
2212-
pid = mingw_spawnv(prog, (const char **)argv2, 1);
2213+
pid = mingw_spawnv(prog, (const char **)argv2, interpr);
22132214
if (pid >= 0) {
22142215
int status;
22152216
if (waitpid(pid, &status, 0) < 0)
@@ -2233,7 +2234,7 @@ int mingw_execv(const char *cmd, char *const *argv)
22332234
int exec_id;
22342235

22352236
exec_id = trace2_exec(cmd, (const char **)argv);
2236-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2237+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
22372238
if (pid < 0) {
22382239
trace2_exec_result(exec_id, -1);
22392240
return -1;

0 commit comments

Comments
 (0)