More specific error message for EACCES during mount()
authorRobert Swiecki <swiecki@google.com>
Tue, 1 Mar 2016 14:02:33 +0000 (15:02 +0100)
committerRobert Swiecki <swiecki@google.com>
Tue, 1 Mar 2016 14:02:33 +0000 (15:02 +0100)
contain.c
net.c

index c1036030b4849e568c92dcdc219a21966ed21e8f..a164e6459cda45cf4c4066c94c186cce691612cf 100644 (file)
--- a/contain.c
+++ b/contain.c
@@ -230,7 +230,7 @@ static bool containNotIsDir(const char *path)
        return true;
 }
 
-static bool containMount(struct mounts_t *mpt, const char *dst)
+static bool containMount(struct nsjconf_t *nsjconf, struct mounts_t *mpt, const char *dst)
 {
        LOG_D("Mounting '%s' on '%s' (type:'%s', flags:0x%tx)", mpt->src, dst, mpt->fs_type,
              mpt->flags);
@@ -251,7 +251,13 @@ static bool containMount(struct mounts_t *mpt, const char *dst)
        }
 
        if (mount(mpt->src, dst, mpt->fs_type, mpt->flags, mpt->options) == -1) {
-               PLOG_E("mount('%s', '%s', type='%s')", mpt->src, dst, mpt->fs_type);
+               if (errno == EACCES) {
+                       PLOG_E
+                           ("mount('%s', '%s', type='%s') failed. Try fixing this problem by applying 'chmod o+x' to the '%s' directory and its ancestors",
+                            mpt->src, dst, mpt->fs_type, nsjconf->chroot);
+               } else {
+                       PLOG_E("mount('%s', '%s', type='%s') failed", mpt->src, dst, mpt->fs_type);
+               }
                return false;
        }
        return true;
@@ -302,7 +308,7 @@ bool containMountFS(struct nsjconf_t * nsjconf)
        TAILQ_FOREACH(p, &nsjconf->mountpts, pointers) {
                char dst[PATH_MAX];
                snprintf(dst, sizeof(dst), "%s/%s", newrootdir, p->dst);
-               if (containMount(p, dst) == false) {
+               if (containMount(nsjconf, p, dst) == false) {
                        return false;
                }
        }
diff --git a/net.c b/net.c
index 01abc87e60ba8fd702a85a7a10e1488e41c193d4..95022cc6a724a52eb242987d4df450ef1c79388a 100644 (file)
--- a/net.c
+++ b/net.c
@@ -362,7 +362,7 @@ bool netConfigureVs(struct nsjconf_t * nsjconf)
                return false;
        }
        if (addr.s_addr == INADDR_ANY) {
-               LOG_I("IP address for interface '%s' not set", IFACE_NAME);
+               LOG_I("IPv4 address for interface '%s' not set", IFACE_NAME);
                return true;
        }
 
@@ -376,7 +376,7 @@ bool netConfigureVs(struct nsjconf_t * nsjconf)
        }
 
        if (inet_pton(AF_INET, nsjconf->iface_vs_nm, &addr) != 1) {
-               PLOG_E("Cannot convert '%s' into an IPv4 netmask", nsjconf->iface_vs_nm);
+               PLOG_E("Cannot convert '%s' into a IPv4 netmask", nsjconf->iface_vs_nm);
                close(sock);
                return false;
        }
@@ -393,13 +393,12 @@ bool netConfigureVs(struct nsjconf_t * nsjconf)
        }
 
        if (inet_pton(AF_INET, nsjconf->iface_vs_gw, &addr) != 1) {
-               PLOG_E("Cannot convert '%s' into an IPv4 GW address", nsjconf->iface_vs_gw);
+               PLOG_E("Cannot convert '%s' into a IPv4 GW address", nsjconf->iface_vs_gw);
                close(sock);
                return false;
        }
        if (addr.s_addr == INADDR_ANY) {
-               LOG_I("Gateway address for '%s' is 0.0.0.0. Not adding the default route",
-                     IFACE_NAME);
+               LOG_I("Gateway address for '%s' is not set", IFACE_NAME);
                return true;
        }
 
@@ -417,6 +416,7 @@ bool netConfigureVs(struct nsjconf_t * nsjconf)
        sgate->sin_addr = addr;
 
        rt.rt_flags = RTF_UP | RTF_GATEWAY;
+       rt.rt_dev = IFACE_NAME;
 
        if (ioctl(sock, SIOCADDRT, &rt) == -1) {
                PLOG_E("ioctl(SIOCADDRT, '%s')", nsjconf->iface_vs_gw);