Use NULL as src for mounting proc and tmpfs
authorJagger <robert@swiecki.net>
Sat, 18 Jun 2016 23:35:06 +0000 (01:35 +0200)
committerJagger <robert@swiecki.net>
Sat, 18 Jun 2016 23:35:06 +0000 (01:35 +0200)
cmdline.c
mount.c

index 7c58fdc250673f2f5d9e64da01c97580bc40b2dd..7b77f51ab1468eb15db24fcdd2d3ebaaa08fde92 100644 (file)
--- a/cmdline.c
+++ b/cmdline.c
@@ -556,7 +556,7 @@ bool cmdlineParse(int argc, char *argv[], struct nsjconf_t * nsjconf)
                case 'T':
                        {
                                struct mounts_t *p = utilMalloc(sizeof(struct mounts_t));
-                               p->src = "/";
+                               p->src = NULL;
                                p->dst = optarg;
                                p->flags = 0;
                                p->options = cmdlineTmpfsSz;
@@ -612,7 +612,7 @@ bool cmdlineParse(int argc, char *argv[], struct nsjconf_t * nsjconf)
 
        if (nsjconf->mount_proc == true) {
                struct mounts_t *p = utilMalloc(sizeof(struct mounts_t));
-               p->src = "/proc";
+               p->src = NULL;
                p->dst = "/proc";
                p->flags = 0;
                p->options = "";
@@ -633,6 +633,17 @@ bool cmdlineParse(int argc, char *argv[], struct nsjconf_t * nsjconf)
                        p->flags |= MS_RDONLY;
                }
                TAILQ_INSERT_HEAD(&nsjconf->mountpts, p, pointers);
+       } else {
+               struct mounts_t *p = utilMalloc(sizeof(struct mounts_t));
+               p->src = NULL;
+               p->dst = "/";
+               p->flags = 0;
+               p->options = "";
+               p->fs_type = "tmpfs";
+               if (nsjconf->is_root_rw == false) {
+                       p->flags |= MS_RDONLY;
+               }
+               TAILQ_INSERT_HEAD(&nsjconf->mountpts, p, pointers);
        }
 
        if (logInitLogFile(nsjconf, logfile, nsjconf->verbose) == false) {
diff --git a/mount.c b/mount.c
index 1fe466b9e19156a1c001637dced3dacd0497b3a2..ce6b938168c7cfe23c2d7923a06d95853c2ecc61 100644 (file)
--- a/mount.c
+++ b/mount.c
 
 static bool mountIsDir(const char *path)
 {
-       if (path == NULL || strcmp(path, "none") == 0) {
-               return false;
+       /*
+        *  If the source dir is NULL, we assume it's a dir (for /proc and tmpfs)
+        */
+       if (path == NULL) {
+               return true;
        }
        struct stat st;
        if (stat(path, &st) == -1) {
@@ -57,7 +60,7 @@ static bool mountIsDir(const char *path)
 // stat() failure
 static bool mountNotIsDir(const char *path)
 {
-       if (path == NULL || strcmp(path, "none") == 0) {
+       if (path == NULL) {
                return false;
        }
        struct stat st;
@@ -91,7 +94,11 @@ static bool mountMount(struct nsjconf_t *nsjconf, struct mounts_t *mpt, const ch
                }
        }
 
-       if (mount(mpt->src, dst, mpt->fs_type, mpt->flags, mpt->options) == -1) {
+       /*
+        * Initially mount it as RW, it will be remounted later on if needed
+        */
+       unsigned long flags = mpt->flags & ~(MS_RDONLY);
+       if (mount(mpt->src, dst, mpt->fs_type, flags, mpt->options) == -1) {
                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",
@@ -146,7 +153,7 @@ static bool mountInitNsInternal(struct nsjconf_t *nsjconf)
        }
 
        const char *const destdir = "/tmp";
-       if (mount("none", destdir, "tmpfs", 0, NULL) == -1) {
+       if (mount(NULL, destdir, "tmpfs", 0, NULL) == -1) {
                PLOG_E("mount('%s', 'tmpfs'", destdir);
                return false;
        }