]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
LXC: Check the existence of dir before resolving symlinks
authorChen Hanxiao <chenhanxiao@cn.fujitsu.com>
Mon, 23 Sep 2013 10:22:17 +0000 (11:22 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Mon, 23 Sep 2013 10:22:17 +0000 (11:22 +0100)
If a dir does not exist, raise an immediate error in logs
rather than letting virFileResolveAllLinks fail, since this
gives better error reporting to the user.

Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
src/lxc/lxc_container.c

index a979452a45d61c33fa5f0ff9e3331ff494ab4cc5..c60f5d8a5dd78eab396cc89f56f51d39dafb2439 100644 (file)
@@ -1696,6 +1696,7 @@ static int lxcContainerResolveSymlinks(virDomainDefPtr vmDef)
 {
     char *newroot;
     size_t i;
+    char ebuf[1024];
 
     VIR_DEBUG("Resolving symlinks");
 
@@ -1703,6 +1704,13 @@ static int lxcContainerResolveSymlinks(virDomainDefPtr vmDef)
         virDomainFSDefPtr fs = vmDef->fss[i];
         if (!fs->src)
             continue;
+
+        if (access(fs->src, F_OK)) {
+            VIR_DEBUG("Failed to access '%s': %s", fs->src,
+                      virStrerror(errno, ebuf, sizeof(ebuf)));
+            return -1;
+        }
+
         VIR_DEBUG("Resolving '%s'", fs->src);
         if (virFileResolveAllLinks(fs->src, &newroot) < 0) {
             VIR_DEBUG("Failed to resolve symlink at %s", fs->src);