[lxc-devel] [lxc/master] dir_detect: warn on eperm

hallyn on Github lxc-bot at linuxcontainers.org
Thu Dec 14 19:18:14 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 579 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20171214/4b2e746d/attachment.bin>
-------------- next part --------------
From 06d645857d82746a219440e8c5015b81eda8b486 Mon Sep 17 00:00:00 2001
From: Serge Hallyn <shallyn at cisco.com>
Date: Thu, 14 Dec 2017 13:16:02 -0600
Subject: [PATCH] dir_detect: warn on eperm

if user has lxc.rootfs.path = /some/path/foo, but can't access
some piece of that path, then we'll get an unhelpful "failed to
mount" without any indication of the problem.

At least show that there is a permission problem.

Signed-off-by: Serge Hallyn <shallyn at cisco.com>
---
 src/lxc/storage/dir.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/lxc/storage/dir.c b/src/lxc/storage/dir.c
index fd2e07526..60a64abff 100644
--- a/src/lxc/storage/dir.c
+++ b/src/lxc/storage/dir.c
@@ -136,10 +136,19 @@ int dir_destroy(struct lxc_storage *orig)
 
 bool dir_detect(const char *path)
 {
+	struct stat statbuf;
+	int ret;
+
 	if (!strncmp(path, "dir:", 4))
 		return true;
 
-	if (is_dir(path))
+	int ret = stat(path, &statbuf);
+	if (ret == -1 && errno == EPERM) {
+		SYSERROR("dir_detect: failed to look at \"%s\"", path);
+		return false;
+	}
+
+	if (ret == 0 && S_ISDIR(statbuf.st_mode))
 		return true;
 
 	return false;


More information about the lxc-devel mailing list