Add locked mount flags during remounting
authorRobert Swiecki <swiecki@google.com>
Tue, 1 Mar 2016 14:36:32 +0000 (15:36 +0100)
committerRobert Swiecki <swiecki@google.com>
Tue, 1 Mar 2016 14:36:32 +0000 (15:36 +0100)
cmdline.c
contain.c

index 4ba2cea8c99134a78d65c265eaa8fe8c62df555d..15cac7f0a4032a5ac47cda8447db12bd1791a894 100644 (file)
--- a/cmdline.c
+++ b/cmdline.c
@@ -507,7 +507,7 @@ bool cmdlineParse(int argc, char *argv[], struct nsjconf_t * nsjconf)
                                struct mounts_t *p = utilMalloc(sizeof(struct mounts_t));
                                p->src = optarg;
                                p->dst = cmdlineSplitStrByColon(optarg);
-                               p->flags = MS_BIND | MS_REC | MS_PRIVATE | MS_RDONLY;
+                               p->flags = MS_BIND | MS_REC | MS_RDONLY;
                                p->options = "";
                                p->fs_type = "";
                                TAILQ_INSERT_TAIL(&nsjconf->mountpts, p, pointers);
@@ -518,7 +518,7 @@ bool cmdlineParse(int argc, char *argv[], struct nsjconf_t * nsjconf)
                                struct mounts_t *p = utilMalloc(sizeof(struct mounts_t));
                                p->src = optarg;
                                p->dst = cmdlineSplitStrByColon(optarg);
-                               p->flags = MS_BIND | MS_REC | MS_PRIVATE;
+                               p->flags = MS_BIND | MS_REC;
                                p->options = "";
                                p->fs_type = "";
                                TAILQ_INSERT_TAIL(&nsjconf->mountpts, p, pointers);
@@ -594,7 +594,7 @@ bool cmdlineParse(int argc, char *argv[], struct nsjconf_t * nsjconf)
                struct mounts_t *p = utilMalloc(sizeof(struct mounts_t));
                p->src = nsjconf->chroot;
                p->dst = "/";
-               p->flags = MS_BIND | MS_REC | MS_PRIVATE;
+               p->flags = MS_BIND | MS_REC;
                p->options = "";
                p->fs_type = "";
                if (nsjconf->is_root_rw == false) {
index a164e6459cda45cf4c4066c94c186cce691612cf..a0ec7fdf38d1ecd097b63722bc53ad8e76f75010 100644 (file)
--- a/contain.c
+++ b/contain.c
@@ -38,6 +38,7 @@
 #include <sys/prctl.h>
 #include <sys/resource.h>
 #include <sys/stat.h>
+#include <sys/statvfs.h>
 #include <sys/syscall.h>
 #include <sys/time.h>
 #include <unistd.h>
@@ -265,11 +266,17 @@ static bool containMount(struct nsjconf_t *nsjconf, struct mounts_t *mpt, const
 
 static bool containRemountRO(struct mounts_t *mpt)
 {
+       struct statvfs vfs;
+       if (statvfs(mpt->dst, &vfs) == -1) {
+               PLOG_E("statvfs('%s')", mpt->dst);
+               return false;
+       }
+
        if (mpt->flags &= MS_RDONLY) {
                LOG_D("Re-mounting RO '%s'", mpt->dst);
                if (mount
                    (mpt->dst, mpt->dst, NULL,
-                    MS_REC | MS_BIND | MS_PRIVATE | MS_REMOUNT | MS_RDONLY, 0) == -1) {
+                    MS_BIND | MS_REMOUNT | MS_RDONLY | vfs.f_flag, 0) == -1) {
                        PLOG_E("mount('%s', MS_REC|MS_BIND|MS_REMOUNT|MS_RDONLY)", mpt->dst);
                        return false;
                }