提交 51fc5655 编写于 作者: E Eric Blake

util: honor anchored names when searching for executables

I got bit in a debugging session on an uninstalled libvirtd; the
code tried to call out to the installed $LIBEXECDIR/libvirt_iohelper
instead of my just-built version.  So I set a breakpoint and altered
the binary name to be "./src/libvirt_iohelper", and it still failed
because I don't have "." on my PATH.

According to POSIX, execvp only searches PATH if the name does
not contain a slash.  Since we are trying to mimic that behavior,
an anchored name should be relative to the current working dir.

This tightens existing behavior, but most callers already pass
an absolute name or a name with no slashes, so it probably won't
be noticeable.

* src/util/util.c (virFindFileInPath): Anchored relative names do
not invoke a PATH search.
上级 83d768fa
...@@ -578,7 +578,7 @@ int virFileResolveLink(const char *linkpath, ...@@ -578,7 +578,7 @@ int virFileResolveLink(const char *linkpath,
*/ */
char *virFindFileInPath(const char *file) char *virFindFileInPath(const char *file)
{ {
char *path; char *path = NULL;
char *pathiter; char *pathiter;
char *pathseg; char *pathseg;
char *fullpath = NULL; char *fullpath = NULL;
...@@ -596,6 +596,15 @@ char *virFindFileInPath(const char *file) ...@@ -596,6 +596,15 @@ char *virFindFileInPath(const char *file)
return NULL; return NULL;
} }
/* If we are passed an anchored path (containing a /), then there
* is no path search - it must exist in the current directory
*/
if (strchr(file, '/')) {
if (virFileIsExecutable(file))
ignore_value(virFileAbsPath(file, &path));
return path;
}
/* copy PATH env so we can tweak it */ /* copy PATH env so we can tweak it */
path = getenv("PATH"); path = getenv("PATH");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册