* cygheap.h (cygheap_fdmanip::cygheap_fdmanip): Clear fh.
(cygheap_fdmanip::isopen): New method. * syscalls.cc (_read): Avoid accessing closed fd. * path.h (fe_types): New enum. (path_conv::set_path): New method. (find_exec): Change null_if_not_found argument to something more generic. * spawn.cc (find_exec): Default to returning the POSIX path rather than the windows path, unless instructed otherwise. (spawn_guts): Force call to find_exec to use native paths. * dlfcn.cc (check_path_access): Accommodate new find_exec arguments. * environ.h (win_env::get_posix): New method.
This commit is contained in:
@ -84,21 +84,34 @@ perhaps_suffix (const char *prog, path_conv &buf)
|
||||
|
||||
const char * __stdcall
|
||||
find_exec (const char *name, path_conv& buf, const char *mywinenv,
|
||||
int null_if_notfound, const char **known_suffix)
|
||||
unsigned opt, const char **known_suffix)
|
||||
{
|
||||
const char *suffix = "";
|
||||
debug_printf ("find_exec (%s)", name);
|
||||
char *retval = buf;
|
||||
char tmp[MAX_PATH];
|
||||
const char *posix = (opt & FE_NATIVE) ? NULL : name;
|
||||
bool has_slash = strchr (name, '/');
|
||||
|
||||
/* Check to see if file can be opened as is first.
|
||||
Win32 systems always check . first, but PATH may not be set up to
|
||||
do this. */
|
||||
if ((suffix = perhaps_suffix (name, buf)) != NULL)
|
||||
goto out;
|
||||
if ((has_slash || opt & FE_CWD)
|
||||
&& (suffix = perhaps_suffix (name, buf)) != NULL)
|
||||
{
|
||||
if (posix && !has_slash)
|
||||
{
|
||||
tmp[0] = '.';
|
||||
tmp[1] = '/';
|
||||
strcpy (tmp + 2, name);
|
||||
posix = tmp;
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
|
||||
win_env *winpath;
|
||||
const char *path;
|
||||
char tmp[MAX_PATH];
|
||||
const char *posix_path;
|
||||
|
||||
/* Return the error condition if this is an absolute path or if there
|
||||
is no PATH to search. */
|
||||
@ -111,14 +124,17 @@ find_exec (const char *name, path_conv& buf, const char *mywinenv,
|
||||
|
||||
debug_printf ("%s%s", mywinenv, path);
|
||||
|
||||
posix = (opt & FE_NATIVE) ? NULL : tmp;
|
||||
posix_path = winpath->get_posix () - 1;
|
||||
/* Iterate over the specified path, looking for the file with and
|
||||
without executable extensions. */
|
||||
do
|
||||
{
|
||||
posix_path++;
|
||||
char *eotmp = strccpy (tmp, &path, ';');
|
||||
/* An empty path or '.' means the current directory, but we've
|
||||
already tried that. */
|
||||
if (tmp[0] == '\0' || (tmp[0] == '.' && tmp[1] == '\0'))
|
||||
if (opt & FE_CWD && (tmp[0] == '\0' || (tmp[0] == '.' && tmp[1] == '\0')))
|
||||
continue;
|
||||
|
||||
*eotmp++ = '\\';
|
||||
@ -127,19 +143,32 @@ find_exec (const char *name, path_conv& buf, const char *mywinenv,
|
||||
debug_printf ("trying %s", tmp);
|
||||
|
||||
if ((suffix = perhaps_suffix (tmp, buf)) != NULL)
|
||||
goto out;
|
||||
{
|
||||
if (posix == tmp)
|
||||
{
|
||||
eotmp = strccpy (tmp, &posix_path, ':');
|
||||
if (eotmp == tmp)
|
||||
*eotmp++ = '.';
|
||||
*eotmp++ = '/';
|
||||
strcpy (eotmp, name);
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
while (*path && *++path);
|
||||
while (*path && *++path && (posix_path = strchr (posix_path, ':')));
|
||||
|
||||
errout:
|
||||
posix = NULL;
|
||||
/* Couldn't find anything in the given path.
|
||||
Take the appropriate action based on null_if_not_found. */
|
||||
if (null_if_notfound)
|
||||
if (opt & FE_NNF)
|
||||
retval = NULL;
|
||||
else
|
||||
else if (opt & FE_NATIVE)
|
||||
buf.check (name);
|
||||
|
||||
out:
|
||||
if (posix)
|
||||
buf.set_path (posix);
|
||||
debug_printf ("%s = find_exec (%s)", (char *) buf, name);
|
||||
if (known_suffix)
|
||||
*known_suffix = suffix ?: strchr (buf, '\0');
|
||||
@ -466,7 +495,9 @@ spawn_guts (HANDLE hToken, const char * prog_arg, const char *const *argv,
|
||||
if (arg1)
|
||||
newargv.unshift (arg1);
|
||||
|
||||
find_exec (pgm, real_path, "PATH=", 0, &ext);
|
||||
/* FIXME: This should not be using FE_NATIVE. It should be putting
|
||||
the posix path on the argv list. */
|
||||
find_exec (pgm, real_path, "PATH=", FE_NATIVE, &ext);
|
||||
newargv.unshift (real_path, 1);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user