Skip to content

Commit dfbdd01

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 faf1f46 commit dfbdd01

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

19681968
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1969-
const char *dir,
1970-
int prepend_cmd, int fhin, int fhout, int fherr)
1969+
const char *dir, const char *prepend_cmd,
1970+
int fhin, int fhout, int fherr)
19711971
{
19721972
static int restrict_handle_inheritance = -1;
19731973
STARTUPINFOEXW si;
@@ -2058,9 +2058,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
20582058
/* concatenate argv, quoting args as we go */
20592059
strbuf_init(&args, 0);
20602060
if (prepend_cmd) {
2061-
char *quoted = (char *)quote_arg(cmd);
2061+
char *quoted = (char *)quote_arg(prepend_cmd);
20622062
strbuf_addstr(&args, quoted);
2063-
if (quoted != cmd)
2063+
if (quoted != prepend_cmd)
20642064
free(quoted);
20652065
}
20662066
for (; *argv; argv++) {
@@ -2219,7 +2219,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
22192219
return (pid_t)pi.dwProcessId;
22202220
}
22212221

2222-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2222+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2223+
const char *prepend_cmd)
22232224
{
22242225
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
22252226
}
@@ -2247,14 +2248,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
22472248
pid = -1;
22482249
}
22492250
else {
2250-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2251+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
22512252
fhin, fhout, fherr);
22522253
free(iprog);
22532254
}
22542255
argv[0] = argv0;
22552256
}
22562257
else
2257-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2258+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
22582259
fhin, fhout, fherr);
22592260
free(prog);
22602261
}
@@ -2279,7 +2280,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
22792280
argv2[0] = (char *)cmd; /* full path to the script file */
22802281
COPY_ARRAY(&argv2[1], &argv[1], argc);
22812282
exec_id = trace2_exec(prog, (const char **)argv2);
2282-
pid = mingw_spawnv(prog, (const char **)argv2, 1);
2283+
pid = mingw_spawnv(prog, (const char **)argv2, interpr);
22832284
if (pid >= 0) {
22842285
int status;
22852286
if (waitpid(pid, &status, 0) < 0)
@@ -2303,7 +2304,7 @@ int mingw_execv(const char *cmd, char *const *argv)
23032304
int exec_id;
23042305

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

0 commit comments

Comments
 (0)