* dlfcn.cc (check_path_access): Drop FE_NATIVE from find_exec call.

(gfpod_helper): Drop equality sign from environment variable name
	in call to check_path_access.
	* exec.cc (execlp): Drop equality sign from environment variable name
	in call to find_exec.
	(execvp): Ditto.
	(execvpe): Ditto.
	* path.h (enum fe_types): Drop FE_NATIVE.
	(find_exec): Rename third paramter in declaration from search.  Drop
	equality sign from default value.
	* spawn.cc (perhaps_suffix): Add PC_POSIX to path_conv::check call.
	(find_exec): Simplify function.  Iterate over POSIX pathlist rather
	than Windows pathlist.  Drop handling of FE_NATIVE flag.  Always fill
	posix path of incoming path_conv buf, unless FE_NNF flag is given.
	(av::setup): Drop equality sign from environment variable name
	in call to find_exec.  Call unshift with normalized_path.
	* winf.cc (av::unshift): Drop conv parameter and code converting
	Windows to POSIX path.
	* winf.h (av::unshift): Accommodate prototype.
This commit is contained in:
Corinna Vinschen 2015-02-11 13:15:59 +00:00
parent 9ab96e0fde
commit 117b1b1edb
7 changed files with 72 additions and 102 deletions

View File

@ -1,3 +1,25 @@
2015-02-11 Corinna Vinschen <corinna@vinschen.de>
* dlfcn.cc (check_path_access): Drop FE_NATIVE from find_exec call.
(gfpod_helper): Drop equality sign from environment variable name
in call to check_path_access.
* exec.cc (execlp): Drop equality sign from environment variable name
in call to find_exec.
(execvp): Ditto.
(execvpe): Ditto.
* path.h (enum fe_types): Drop FE_NATIVE.
(find_exec): Rename third paramter in declaration from search. Drop
equality sign from default value.
* spawn.cc (perhaps_suffix): Add PC_POSIX to path_conv::check call.
(find_exec): Simplify function. Iterate over POSIX pathlist rather
than Windows pathlist. Drop handling of FE_NATIVE flag. Always fill
posix path of incoming path_conv buf, unless FE_NNF flag is given.
(av::setup): Drop equality sign from environment variable name
in call to find_exec. Call unshift with normalized_path.
* winf.cc (av::unshift): Drop conv parameter and code converting
Windows to POSIX path.
* winf.h (av::unshift): Accommodate prototype.
2015-02-10 Corinna Vinschen <corinna@vinschen.de>
* syscalls.cc (fhandler_base::stat_fixup): Generate unique inode number

View File

@ -1,7 +1,7 @@
/* dlfcn.cc
Copyright 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
2010, 2011, 2013, 2014 Red Hat, Inc.
2010, 2011, 2013, 2014, 2015 Red Hat, Inc.
This file is part of Cygwin.
@ -37,7 +37,7 @@ set_dl_error (const char *str)
inline const char *
check_path_access (const char *mywinenv, const char *name, path_conv& buf)
{
return find_exec (name, buf, mywinenv, FE_NNF | FE_NATIVE | FE_DLL);
return find_exec (name, buf, mywinenv, FE_NNF | FE_DLL);
}
/* Search LD_LIBRARY_PATH for dll, if it exists. Search /usr/bin and /usr/lib
@ -47,7 +47,7 @@ gfpod_helper (const char *name, path_conv &real_filename)
{
if (strchr (name, '/'))
real_filename.check (name, PC_SYM_FOLLOW | PC_NULLEMPTY);
else if (!check_path_access ("LD_LIBRARY_PATH=", name, real_filename))
else if (!check_path_access ("LD_LIBRARY_PATH", name, real_filename))
check_path_access ("/usr/bin:/usr/lib", name, real_filename);
if (!real_filename.exists ())
real_filename.error = ENOENT;

View File

@ -1,7 +1,7 @@
/* exec.cc: exec system call support.
Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008,
2009, 2011, 2012 Red Hat, Inc.
2009, 2011, 2012, 2015 Red Hat, Inc.
This file is part of Cygwin.
@ -76,7 +76,7 @@ execlp (const char *file, const char *arg0, ...)
va_end (args);
MALLOC_CHECK;
return spawnve (_P_OVERLAY | _P_PATH_TYPE_EXEC,
find_exec (file, buf, "PATH=", FE_NNF) ?: "",
find_exec (file, buf, "PATH", FE_NNF) ?: "",
(char * const *) argv, cur_environ ());
}
@ -102,7 +102,7 @@ execvp (const char *file, char * const *argv)
MALLOC_CHECK;
return spawnve (_P_OVERLAY | _P_PATH_TYPE_EXEC,
find_exec (file, buf, "PATH=", FE_NNF) ?: "",
find_exec (file, buf, "PATH", FE_NNF) ?: "",
argv, cur_environ ());
}
@ -113,7 +113,7 @@ execvpe (const char *file, char * const *argv, char *const *envp)
MALLOC_CHECK;
return spawnve (_P_OVERLAY | _P_PATH_TYPE_EXEC,
find_exec (file, buf, "PATH=", FE_NNF) ?: "",
find_exec (file, buf, "PATH", FE_NNF) ?: "",
argv, envp);
}

View File

@ -1,7 +1,7 @@
/* path.h: path data structures
Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
2008, 2009, 2010, 2011, 2012, 2013 Red Hat, Inc.
2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Red Hat, Inc.
This file is part of Cygwin.
@ -414,12 +414,11 @@ enum fe_types
{
FE_NADA = 0, /* Nothing special */
FE_NNF = 1, /* Return NULL if not found */
FE_NATIVE = 2, /* Return native path in path_conv struct */
FE_CWD = 4, /* Search CWD for program */
FE_DLL = 8 /* Search for DLLs, not executables. */
};
const char *__reg3 find_exec (const char *name, path_conv& buf,
const char *winenv = "PATH=",
const char *search = "PATH",
unsigned opt = FE_NADA,
const char **known_suffix = NULL);

View File

@ -1,7 +1,7 @@
/* spawn.cc
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Red Hat, Inc.
2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Red Hat, Inc.
This file is part of Cygwin.
@ -53,7 +53,7 @@ perhaps_suffix (const char *prog, path_conv& buf, int& err, unsigned opt)
err = 0;
debug_printf ("prog '%s'", prog);
buf.check (prog, PC_SYM_FOLLOW | PC_NULLEMPTY,
buf.check (prog, PC_SYM_FOLLOW | PC_NULLEMPTY | PC_POSIX,
(opt & FE_DLL) ? stat_suffixes : exe_suffixes);
if (buf.isdir ())
@ -75,124 +75,86 @@ perhaps_suffix (const char *prog, path_conv& buf, int& err, unsigned opt)
return ext;
}
/* Find an executable name, possibly by appending known executable
suffixes to it. The win32-translated name is placed in 'buf'.
Any found suffix is returned in known_suffix.
If the file is not found and !null_if_not_found then the win32 version
of name is placed in buf and returned. Otherwise the contents of buf
is undefined and NULL is returned. */
/* Find an executable name, possibly by appending known executable suffixes
to it. The path_conv struct 'buf' is filled and contains both, win32 and
posix path of the file.. Any found suffix is returned in known_suffix.
If the file is not found and !FE_NNF then the win32 version of name is
placed in buf and returned. Otherwise the contents of buf is undefined
and NULL is returned. */
const char * __reg3
find_exec (const char *name, path_conv& buf, const char *mywinenv,
find_exec (const char *name, path_conv& buf, const char *search,
unsigned opt, const char **known_suffix)
{
const char *suffix = "";
debug_printf ("find_exec (%s)", name);
const char *retval;
const char *retval = NULL;
tmp_pathbuf tp;
char *tmp_path;
char *tmp = tp.c_get ();
const char *posix = (opt & FE_NATIVE) ? NULL : name;
bool has_slash = !!strpbrk (name, "/\\");
int err = 0;
/* 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. */
debug_printf ("find_exec (%s)", name);
/* Check to see if file can be opened as is first. */
if ((has_slash || opt & FE_CWD)
&& (suffix = perhaps_suffix (name, buf, err, opt)) != NULL)
{
if (posix && !has_slash)
{
tmp[0] = '.';
tmp[1] = '/';
strcpy (tmp + 2, name);
posix = tmp;
}
retval = buf.get_win32 ();
goto out;
}
win_env *winpath;
const char *path;
const char *posix_path;
posix = (opt & FE_NATIVE) ? NULL : tmp;
if (strchr (mywinenv, '/'))
{
/* it's not really an environment variable at all */
int n = cygwin_conv_path_list (CCP_POSIX_TO_WIN_A, mywinenv, NULL, 0);
char *s = (char *) alloca (n);
if (cygwin_conv_path_list (CCP_POSIX_TO_WIN_A, mywinenv, s, n))
goto errout;
path = s;
posix_path = mywinenv - 1;
}
else if (has_slash || strchr (name, '\\') || isdrive (name)
|| !(winpath = getwinenv (mywinenv))
|| !(path = winpath->get_native ()) || *path == '\0')
/* Return the error condition if this is an absolute path or if there
is no PATH to search. */
/* If it starts with a slash, it's a PATH-like pathlist. Otherwise it's
the name of an environment variable. */
if (strchr (search, '/'))
*stpncpy (tmp, search, NT_MAX_PATH - 1) = '\0';
else if (has_slash || isdrive (name) || !(path = getenv (search)) || !*path)
goto errout;
else
posix_path = winpath->get_posix () - 1;
*stpncpy (tmp, path, NT_MAX_PATH - 1) = '\0';
debug_printf ("%s%s", mywinenv, path);
/* Iterate over the specified path, looking for the file with and without
executable extensions. */
path = tmp;
debug_printf ("searchpath %s", path);
tmp_path = tp.c_get ();
do
{
posix_path++;
char *eotmp = strccpy (tmp, &path, ';');
char *eotmp = strccpy (tmp_path, &path, ':');
/* An empty path or '.' means the current directory, but we've
already tried that. */
if (opt & FE_CWD && (tmp[0] == '\0' || (tmp[0] == '.' && tmp[1] == '\0')))
if ((opt & FE_CWD) && (tmp_path[0] == '\0'
|| (tmp_path[0] == '.' && tmp_path[1] == '\0')))
continue;
*eotmp++ = '\\';
*eotmp++ = '/';
strcpy (eotmp, name);
debug_printf ("trying %s", tmp);
debug_printf ("trying %s", tmp_path);
int err1;
if ((suffix = perhaps_suffix (tmp, buf, err1, opt)) != NULL)
if ((suffix = perhaps_suffix (tmp_path, buf, err1, opt)) != NULL)
{
if (buf.has_acls () && check_file_access (buf, X_OK, true))
continue;
if (posix == tmp)
{
eotmp = strccpy (tmp, &posix_path, ':');
if (eotmp == tmp)
*eotmp++ = '.';
*eotmp++ = '/';
strcpy (eotmp, name);
}
retval = buf.get_win32 ();
goto out;
}
}
while (*path && *++path && (posix_path = strchr (posix_path, ':')));
while (*path && *++path);
errout:
posix = NULL;
/* Couldn't find anything in the given path.
Take the appropriate action based on null_if_not_found. */
if (opt & FE_NNF)
retval = NULL;
else if (!(opt & FE_NATIVE))
retval = name;
else
Take the appropriate action based on FE_NNF. */
if (!(opt & FE_NNF))
{
buf.check (name);
buf.check (name, PC_SYM_FOLLOW | PC_POSIX);
retval = buf.get_win32 ();
}
out:
if (posix)
retval = buf.set_path (posix);
debug_printf ("%s = find_exec (%s)", (char *) buf.get_win32 (), name);
if (known_suffix)
*known_suffix = suffix ?: strchr (buf.get_win32 (), '\0');
@ -1238,10 +1200,8 @@ av::setup (const char *prog_arg, path_conv& real_path, const char *ext,
if (arg1)
unshift (arg1);
/* 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);
unshift (real_path.get_win32 (), 1);
find_exec (pgm, real_path, "PATH", FE_NADA, &ext);
unshift (real_path.normalized_path);
}
if (real_path.iscygexec ())
dup_all ();

View File

@ -1,6 +1,6 @@
/* winf.cc
Copyright 2003, 2004, 2005, 2006, 2008, 2009, 2013, 2014 Red Hat, Inc.
Copyright 2003, 2004, 2005, 2006, 2008, 2009, 2013, 2014, 2015 Red Hat, Inc.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
@ -126,7 +126,7 @@ linebuf::fromargv (av& newargv, const char *real_path, bool cmdlenoverflow_ok)
}
int
av::unshift (const char *what, int conv)
av::unshift (const char *what)
{
char **av;
av = (char **) crealloc (argv, (argc + 2) * sizeof (char *));
@ -135,17 +135,6 @@ av::unshift (const char *what, int conv)
argv = av;
memmove (argv + 1, argv, (argc + 1) * sizeof (char *));
tmp_pathbuf tp;
char *buf = tp.c_get ();
if (conv)
{
cygwin_conv_path (CCP_WIN_A_TO_POSIX | CCP_RELATIVE, what, buf,
NT_MAX_PATH);
char *p = strchr (buf, '\0') - 4;
if (p > buf && ascii_strcasematch (p, ".exe"))
*p = '\0';
what = buf;
}
*argv = cstrdup1 (what);
calloced++;
argc++;

View File

@ -1,6 +1,6 @@
/* winf.h
Copyright 2006, 2007, 2009, 2011, 2013 Red Hat, Inc.
Copyright 2006, 2007, 2009, 2011, 2013, 2015 Red Hat, Inc.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
@ -41,7 +41,7 @@ class av
cfree (argv);
}
}
int unshift (const char *what, int conv = 0) __reg2;
int unshift (const char *what) __reg2;
operator char **() {return argv;}
void all_calloced () {calloced = argc;}
void replace0_maybe (const char *arg0)