From 9b1952c45a8d014142c3c5d332a2a4c35da0cbd9 Mon Sep 17 00:00:00 2001 Message-Id: <9b1952c45a8d014142c3c5d332a2a4c35da0cbd9.1381871412.git.jdenemar@redhat.com> From: Chen Hanxiao Date: Mon, 14 Oct 2013 16:45:25 +0100 Subject: [PATCH] LXC: Check the existence of dir before resolving symlinks For https://bugzilla.redhat.com/show_bug.cgi?id=927072 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 (cherry picked from commit 9a08e2cbc6933c068310c85354cff75e015f1de0) Signed-off-by: Jiri Denemark --- src/lxc/lxc_container.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 43178e2..f6375b7 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -1668,6 +1668,7 @@ static int lxcContainerResolveSymlinks(virDomainDefPtr vmDef) { char *newroot; size_t i; + char ebuf[1024]; VIR_DEBUG("Resolving symlinks"); @@ -1675,6 +1676,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); -- 1.8.3.2