mount: don't R/O remount mounts which were not mounted (not mandatory)
authorRobert Swiecki <robert@swiecki.net>
Sat, 7 Oct 2017 23:28:45 +0000 (01:28 +0200)
committerRobert Swiecki <robert@swiecki.net>
Sat, 7 Oct 2017 23:28:45 +0000 (01:28 +0200)
cmdline.c
common.h
contain.h
mount.c

index 1189702..9165c1b 100644 (file)
--- a/cmdline.c
+++ b/cmdline.c
@@ -644,8 +644,7 @@ bool cmdlineParse(int argc, char *argv[], struct nsjconf_t * nsjconf)
                                dst = dst ? dst : optarg;
                                if (!mountAddMountPtTail
                                    (nsjconf, /* src= */ optarg, dst, /* fs_type= */ "",
-                                                                                       /* options= */ "", MS_BIND | MS_REC | MS_RDONLY,
-                                                                                       /* isDir= */
+                                    /* options= */ "", MS_BIND | MS_REC | MS_RDONLY, /* isDir= */
                                     NS_DIR_MAYBE, /* mandatory= */ true, NULL, NULL, NULL, 0,
                                     /* is_symlink= */ false)) {
                                        return false;
@@ -658,8 +657,7 @@ bool cmdlineParse(int argc, char *argv[], struct nsjconf_t * nsjconf)
                                if (!mountAddMountPtTail
                                    (nsjconf, /* src= */ optarg, dst, /* fs_type= */ "",
                                     /* options= */ "", MS_BIND | MS_REC, /* isDir= */ NS_DIR_MAYBE,
-                                                                                       /* mandatory= */ true, NULL, NULL, NULL, 0,
-                                                                                       /* is_symlink= */
+                                    /* mandatory= */ true, NULL, NULL, NULL, 0, /* is_symlink= */
                                     false)) {
                                        return false;
                                }
@@ -763,10 +761,10 @@ bool cmdlineParse(int argc, char *argv[], struct nsjconf_t * nsjconf)
                        return false;
                }
        } else {
-               if (!mountAddMountPtHead(nsjconf, /* src= */ NULL, "/", "tmpfs", /* options= */ "",
-                                        nsjconf->is_root_rw ? 0 : MS_RDONLY, /* isDir= */ true,
-                                        /* mandatory= */ true,
-                                        NULL, NULL, NULL, 0, /* is_symlink= */ false)) {
+               if (!mountAddMountPtHead
+                   (nsjconf, /* src= */ NULL, "/", "tmpfs", /* options= */ "",
+                    nsjconf->is_root_rw ? 0 : MS_RDONLY, /* isDir= */ true, /* mandatory= */ true,
+                    NULL, NULL, NULL, 0, /* is_symlink= */ false)) {
                        return false;
                }
        }
index 047df76..bba57b1 100644 (file)
--- a/common.h
+++ b/common.h
@@ -76,6 +76,7 @@ struct mounts_t {
        bool isDir;
        bool isSymlink;
        bool mandatory;
+       bool mounted;
         TAILQ_ENTRY(mounts_t)
         pointers;
 };
index 31c8714..edba108 100644 (file)
--- a/contain.h
+++ b/contain.h
@@ -26,7 +26,7 @@
 
 #include "common.h"
 
-bool containSetupFD(struct nsjconf_t * nsjconf, int fd_in, int fd_out, int fd_err);
+bool containSetupFD(struct nsjconf_t *nsjconf, int fd_in, int fd_out, int fd_err);
 bool containContain(struct nsjconf_t *nsjconf);
 
 #endif                         /* NS_CONTAIN_H */
diff --git a/mount.c b/mount.c
index 0a28817..b134d79 100644 (file)
--- a/mount.c
+++ b/mount.c
@@ -207,6 +207,8 @@ static bool mountMount(struct mounts_t *mpt, const char *newroot, const char *tm
                        PLOG_W("mount('%s') src:'%s' dst:'%s' failed", mountDescribeMountPt(mpt),
                               srcpath, dst);
                }
+       } else {
+               mpt->mounted = true;
        }
 
        if (mpt->src_content && unlink(srcpath) == -1) {
@@ -217,6 +219,9 @@ static bool mountMount(struct mounts_t *mpt, const char *newroot, const char *tm
 
 static bool mountRemountRO(struct mounts_t *mpt)
 {
+       if (!mpt->mounted) {
+               return true;
+       }
        if (mpt->isSymlink == true) {
                return true;
        }
@@ -451,6 +456,7 @@ static bool mountAddMountPt(struct nsjconf_t *nsjconf, bool head, const char *sr
        p->isDir = true;
        p->isSymlink = is_symlink;
        p->mandatory = mandatory;
+       p->mounted = false;
 
        switch (isDir) {
        case NS_DIR_YES: