Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use env as interpreter for all exe and scripts. #3869

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 12 additions & 55 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1530,41 +1530,6 @@ static const char *quote_arg_msys2(const char *arg)
return strbuf_detach(&buf, 0);
}

static const char *parse_interpreter(const char *cmd)
{
static char buf[MAX_PATH];
char *p, *opt;
int n, fd;

/* don't even try a .exe */
n = strlen(cmd);
if (n >= 4 && !strcasecmp(cmd+n-4, ".exe"))
return NULL;

fd = open(cmd, O_RDONLY);
if (fd < 0)
return NULL;
n = read(fd, buf, sizeof(buf)-1);
close(fd);
if (n < 4) /* at least '#!/x' and not error */
return NULL;

if (buf[0] != '#' || buf[1] != '!')
return NULL;
buf[n] = '\0';
p = buf + strcspn(buf, "\r\n");
if (!*p)
return NULL;

*p = '\0';
if (!(p = strrchr(buf+2, '/')) && !(p = strrchr(buf+2, '\\')))
return NULL;
/* strip options */
if ((opt = strchr(p+1, ' ')))
*opt = '\0';
return p+1;
}

/*
* exe_only means that we only want to detect .exe files, but not scripts
* (which do not have an extension)
Expand Down Expand Up @@ -2151,39 +2116,31 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
pid = -1;
}
else {
const char *interpr = parse_interpreter(prog);

if (interpr) {
const char *argv0 = argv[0];
char *iprog = path_lookup(interpr, 1);
const char *interpr = "env.exe";
const char *argv0 = argv[0];
char *iprog = path_lookup(interpr, 1);
if (!iprog) {
errno = ENOENT;
pid = -1;
}
else {
argv[0] = prog;
if (!iprog) {
errno = ENOENT;
pid = -1;
}
else {
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
fhin, fhout, fherr);
free(iprog);
}
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
fhin, fhout, fherr);
free(iprog);
argv[0] = argv0;
}
else
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
fhin, fhout, fherr);
free(prog);
}
return pid;
}

static int try_shell_exec(const char *cmd, char *const *argv)
{
const char *interpr = parse_interpreter(cmd);
const char *interpr = "env.exe";
char *prog;
int pid = 0;

if (!interpr)
return 0;
prog = path_lookup(interpr, 1);
if (prog) {
int exec_id;
Expand Down