maint: fix some compilation issues on non-linux platforms (part 2)

Get rid of the #if __linux__ check in virPidFileReadPathIfAlive that
was preventing a check of a symbolic link in /proc/<pid>/exe on
non-linux platforms against an expected executable. Replace
this with a run-time check testing whether the /proc/<pid>/exe is a
symbolic link and if so call the function doing the comparison
against the expected file the link is supposed to point to.
This commit is contained in:
Stefan Berger 2011-08-16 15:36:22 -04:00
parent f4765b691d
commit 57c7b40b76
4 changed files with 25 additions and 3 deletions

View File

@ -1047,6 +1047,7 @@ virFileExists;
virFileFindMountPoint; virFileFindMountPoint;
virFileHasSuffix; virFileHasSuffix;
virFileIsExecutable; virFileIsExecutable;
virFileIsLink;
virFileLinkPointsTo; virFileLinkPointsTo;
virFileLock; virFileLock;
virFileMakePath; virFileMakePath;

View File

@ -570,6 +570,23 @@ int virFileResolveLink(const char *linkpath,
return *resultpath == NULL ? -1 : 0; return *resultpath == NULL ? -1 : 0;
} }
/*
* Check whether the given file is a link.
* Returns 1 in case of the file being a link, 0 in case it is not
* a link and the negative errno in all other cases.
*/
int virFileIsLink(const char *linkpath)
{
struct stat st;
if (lstat(linkpath, &st) < 0)
return -errno;
return (S_ISLNK(st.st_mode) != 0);
}
/* /*
* Finds a requested executable file in the PATH env. e.g.: * Finds a requested executable file in the PATH env. e.g.:
* "kvm-img" will return "/usr/bin/kvm-img" * "kvm-img" will return "/usr/bin/kvm-img"

View File

@ -78,6 +78,9 @@ int virFileLinkPointsTo(const char *checkLink,
int virFileResolveLink(const char *linkpath, int virFileResolveLink(const char *linkpath,
char **resultpath) ATTRIBUTE_RETURN_CHECK; char **resultpath) ATTRIBUTE_RETURN_CHECK;
int virFileIsLink(const char *linkpath)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
char *virFindFileInPath(const char *file); char *virFindFileInPath(const char *file);
bool virFileExists(const char *file) ATTRIBUTE_NONNULL(1); bool virFileExists(const char *file) ATTRIBUTE_NONNULL(1);

View File

@ -210,10 +210,11 @@ int virPidFileReadPathIfAlive(const char *path,
*pid = -1; *pid = -1;
return 0; return 0;
} }
#ifdef __linux__
if (virFileLinkPointsTo(procpath, binpath) == 0) if (virFileIsLink(procpath) &&
virFileLinkPointsTo(procpath, binpath) == 0)
*pid = -1; *pid = -1;
#endif
VIR_FREE(procpath); VIR_FREE(procpath);
return 0; return 0;