[libvirt] [PATCH]LXC: Check the existence of dir before resolving symlinks

From: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> If dir does not exist, raise a proper error in logs and don't let virFileResolveAllLinks throw itself's exceptions in logs, which may be misleading. Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- 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 a979452..c60f5d8 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -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); -- 1.8.2.1

On Mon, Sep 23, 2013 at 02:46:20PM +0800, Chen Hanxiao wrote:
From: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
If dir does not exist, raise a proper error in logs and don't let virFileResolveAllLinks throw itself's exceptions in logs, which may be misleading.
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- src/lxc/lxc_container.c | 8 ++++++++ 1 file changed, 8 insertions(+)
ACK & pushed. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (2)
-
Chen Hanxiao
-
Daniel P. Berrange