Skip to content

Commit 2de8988

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 b5c2aeb commit 2de8988

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
@@ -1990,8 +1990,8 @@ static int is_msys2_sh(const char *cmd)
19901990
}
19911991

19921992
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1993-
const char *dir,
1994-
int prepend_cmd, int fhin, int fhout, int fherr)
1993+
const char *dir, const char *prepend_cmd,
1994+
int fhin, int fhout, int fherr)
19951995
{
19961996
STARTUPINFOEXW si;
19971997
PROCESS_INFORMATION pi;
@@ -2071,9 +2071,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
20712071
/* concatenate argv, quoting args as we go */
20722072
strbuf_init(&args, 0);
20732073
if (prepend_cmd) {
2074-
char *quoted = (char *)quote_arg(cmd);
2074+
char *quoted = (char *)quote_arg(prepend_cmd);
20752075
strbuf_addstr(&args, quoted);
2076-
if (quoted != cmd)
2076+
if (quoted != prepend_cmd)
20772077
free(quoted);
20782078
}
20792079
for (; *argv; argv++) {
@@ -2193,7 +2193,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
21932193
return (pid_t)pi.dwProcessId;
21942194
}
21952195

2196-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2196+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2197+
const char *prepend_cmd)
21972198
{
21982199
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
21992200
}
@@ -2221,14 +2222,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
22212222
pid = -1;
22222223
}
22232224
else {
2224-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2225+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
22252226
fhin, fhout, fherr);
22262227
free(iprog);
22272228
}
22282229
argv[0] = argv0;
22292230
}
22302231
else
2231-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2232+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
22322233
fhin, fhout, fherr);
22332234
free(prog);
22342235
}
@@ -2253,7 +2254,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
22532254
argv2[0] = (char *)cmd; /* full path to the script file */
22542255
COPY_ARRAY(&argv2[1], &argv[1], argc);
22552256
exec_id = trace2_exec(prog, (const char **)argv2);
2256-
pid = mingw_spawnv(prog, (const char **)argv2, 1);
2257+
pid = mingw_spawnv(prog, (const char **)argv2, interpr);
22572258
if (pid >= 0) {
22582259
int status;
22592260
if (waitpid(pid, &status, 0) < 0)
@@ -2277,7 +2278,7 @@ int mingw_execv(const char *cmd, char *const *argv)
22772278
int exec_id;
22782279

22792280
exec_id = trace2_exec(cmd, (const char **)argv);
2280-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2281+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
22812282
if (pid < 0) {
22822283
trace2_exec_result(exec_id, -1);
22832284
return -1;

0 commit comments

Comments
 (0)