On 08/16/2011 03:25 PM, Eric Blake wrote:
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(a)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.
Pushed with those two fixes.
Stefan