[libvirt] main: fix some compilation issues on non-linux platforms
Eric Blake
eblake at redhat.com
Tue Aug 16 19:25:15 UTC 2011
On 08/16/2011 01:01 PM, Stefan Berger wrote:
>> Following the latter couldn't it just be handled during runtime
>> altogether?
That actually sounds better.
>>
>> Stefan
>>
> Along those lines I propose this patch below:
>
> Signed-off-by: Stefan Berger <stefanb at linux.vnet.ibm.com>
>
> +int virFileIsLink(const char *linkpath)
> +{
> + struct stat st;
> +
> + if (lstat(linkpath, &st) < 0)
> + return -errno;
> +
> + return S_ISLNK(st.st_mode);
S_ISLNK is only guaranteed to return non-zero for links, not 1. You
need to sanitize it:
return S_ISLNK(st.st_mode) != 0;
or
return !!S_ISLNK(st.st_mode);
> +++ libvirt-acl/src/util/util.h
> @@ -78,6 +78,8 @@ int virFileLinkPointsTo(const char *chec
> int virFileResolveLink(const char *linkpath,
> char **resultpath) ATTRIBUTE_RETURN_CHECK;
>
> +int virFileIsLink(const char *linkpath) ATTRIBUTE_RETURN_CHECK;
Also add ATTRIBUTE_NONNULL(1), since lstat(NULL) is invalid.
ACK with those two fixes.
--
Eric Blake eblake at redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
More information about the libvir-list
mailing list