mount: don't R/O remount mounts which were not mounted (not mandatory)

This commit is contained in:
Robert Swiecki 2017-10-08 01:28:45 +02:00
parent 6d29c196ac
commit b7def79d90
4 changed files with 14 additions and 9 deletions

View File

@ -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,9 +761,9 @@ 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,
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;
}

View File

@ -76,6 +76,7 @@ struct mounts_t {
bool isDir;
bool isSymlink;
bool mandatory;
bool mounted;
TAILQ_ENTRY(mounts_t)
pointers;
};

View File

@ -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 */

View File

@ -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: