From 04fa1e9c1f29cd8f2df57ac8763866e43ba98267 Mon Sep 17 00:00:00 2001 From: Jagger Date: Wed, 12 Aug 2015 01:17:54 +0200 Subject: [PATCH] More verbose error messages for mounting files/dirs --- contain.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/contain.c b/contain.c index 7b79775..e9d5a72 100644 --- a/contain.c +++ b/contain.c @@ -196,7 +196,7 @@ static char *findSpecDestination(char *spec) } } -static bool bindMountRW(const char *newrootdir, const char *spec) +static bool bindMountRW(struct nsjconf_t *nsjconf, const char *newrootdir, const char *spec) { char mount_pt[PATH_MAX]; bool success = false; @@ -214,17 +214,19 @@ static bool bindMountRW(const char *newrootdir, const char *spec) PLOG_W("stat('%s')", source); goto cleanup; } - // Create mount_pt dir, only if the source bind mount point is also a directory if (S_ISDIR(st.st_mode)) { + // Create mount_pt dir, only if the source bind mount point is also a directory if (mkdir(mount_pt, 0700) == -1 && errno != EEXIST) { - PLOG_E("mkdir('%s')", mount_pt); + PLOG_E("mkdir('%s') failed. Try creating the '%s/%s' directory manually", mount_pt, + nsjconf->chroot, dest); goto cleanup; } - // For everything else (files, sockets, pipes, devices), create a regular file } else { + // For everything else (files, sockets, pipes, devices), create a regular file int fd = open(mount_pt, O_CREAT | O_RDONLY, 0700); if (fd == -1) { - PLOG_E("creat('%s')", mount_pt); + PLOG_E("creat('%s') failed. Try creating the '%s/%s' file manually", mount_pt, nsjconf->chroot, + dest); goto cleanup; } close(fd); @@ -315,12 +317,12 @@ bool containMountFS(struct nsjconf_t * nsjconf) } } LIST_FOREACH(p, &nsjconf->robindmountpts, pointers) { - if (!bindMountRW(newrootdir, p->value)) { + if (!bindMountRW(nsjconf, newrootdir, p->value)) { return false; } } LIST_FOREACH(p, &nsjconf->rwbindmountpts, pointers) { - if (!bindMountRW(newrootdir, p->value)) { + if (!bindMountRW(nsjconf, newrootdir, p->value)) { return false; } }