Re: main: fix some compilation issues on non-linux platforms

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxxx>

+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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]