cmdline/mount: mount proc at the beginning
authorRobert Swiecki <robert@swiecki.net>
Sat, 7 Oct 2017 21:32:25 +0000 (23:32 +0200)
committerRobert Swiecki <robert@swiecki.net>
Sat, 7 Oct 2017 21:32:25 +0000 (23:32 +0200)
cmdline.c
config.cc
mount.c
mount.h

index cd3f29a..ef112b6 100644 (file)
--- a/cmdline.c
+++ b/cmdline.c
@@ -756,17 +756,17 @@ bool cmdlineParse(int argc, char *argv[], struct nsjconf_t * nsjconf)
        }
 
        if (nsjconf->mount_proc == true) {
-               if (!mountAddMountPt(nsjconf, /* src= */ NULL, "/proc", "proc", "",
-                                    nsjconf->is_root_rw ? 0 : MS_RDONLY,       /* isDir= */
-                                    true,
-                                    /* mandatory= */ true, NULL, NULL, NULL, 0,
-                                    /* is_symlink= */
-                                    false)) {
+               if (!mountAddMountPtHead(nsjconf, /* src= */ NULL, "/proc", "proc", "",
+                                        nsjconf->is_root_rw ? 0 : MS_RDONLY,   /* isDir= */
+                                        true,
+                                        /* mandatory= */ true, NULL, NULL, NULL, 0,
+                                        /* is_symlink= */
+                                        false)) {
                        return false;
                }
        }
        if (nsjconf->chroot != NULL) {
-               if (!mountAddMountPt
+               if (!mountAddMountPtHead
                    (nsjconf, nsjconf->chroot, "/", /* fs_type= */ "", /* options= */ "",
                     nsjconf->is_root_rw ? (MS_BIND | MS_REC) : (MS_BIND | MS_REC | MS_RDONLY),
                     /* isDir= */ true,
@@ -774,12 +774,12 @@ bool cmdlineParse(int argc, char *argv[], struct nsjconf_t * nsjconf)
                        return false;
                }
        } else {
-               if (!mountAddMountPt(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 ab600b9..7097165 100644 (file)
--- a/config.cc
+++ b/config.cc
@@ -232,7 +232,7 @@ static bool configParseInternal(struct nsjconf_t* nsjconf,
             src_content_len = njc.mount(i).src_content().size();
         }
 
-        if (mountAddMountPt(nsjconf, src, dst, fstype, options, flags, isDir,
+        if (mountAddMountPtTail(nsjconf, src, dst, fstype, options, flags, isDir,
                 mandatory, src_env, dst_env, src_content,
                 src_content_len, njc.mount(i).is_symlink())
             == false) {
diff --git a/mount.c b/mount.c
index 08f95a9..0a28817 100644 (file)
--- a/mount.c
+++ b/mount.c
@@ -410,10 +410,10 @@ bool mountInitNs(struct nsjconf_t * nsjconf)
        return false;
 }
 
-bool mountAddMountPt(struct nsjconf_t * nsjconf, const char *src, const char *dst,
-                    const char *fstype, const char *options, uintptr_t flags, isDir_t isDir,
-                    bool mandatory, const char *src_env, const char *dst_env,
-                    const char *src_content, size_t src_content_len, bool is_symlink)
+static bool mountAddMountPt(struct nsjconf_t *nsjconf, bool head, const char *src, const char *dst,
+                           const char *fstype, const char *options, uintptr_t flags, isDir_t isDir,
+                           bool mandatory, const char *src_env, const char *dst_env,
+                           const char *src_content, size_t src_content_len, bool is_symlink)
 {
        struct mounts_t *p = utilCalloc(sizeof(struct mounts_t));
 
@@ -479,11 +479,35 @@ bool mountAddMountPt(struct nsjconf_t * nsjconf, const char *src, const char *ds
        p->src_content = utilMemDup((const uint8_t *)src_content, src_content_len);
        p->src_content_len = src_content_len;
 
-       TAILQ_INSERT_TAIL(&nsjconf->mountpts, p, pointers);
+       if (head) {
+               TAILQ_INSERT_HEAD(&nsjconf->mountpts, p, pointers);
+       } else {
+               TAILQ_INSERT_TAIL(&nsjconf->mountpts, p, pointers);
+       }
 
        return true;
 }
 
+bool mountAddMountPtHead(struct nsjconf_t * nsjconf, const char *src, const char *dst,
+                        const char *fstype, const char *options, uintptr_t flags, isDir_t isDir,
+                        bool mandatory, const char *src_env, const char *dst_env,
+                        const char *src_content, size_t src_content_len, bool is_symlink)
+{
+       return mountAddMountPt(nsjconf, /* head= */ true, src, dst, fstype, options, flags, isDir,
+                              mandatory, src_env, dst_env, src_content, src_content_len,
+                              is_symlink);
+}
+
+bool mountAddMountPtTail(struct nsjconf_t * nsjconf, const char *src, const char *dst,
+                        const char *fstype, const char *options, uintptr_t flags, isDir_t isDir,
+                        bool mandatory, const char *src_env, const char *dst_env,
+                        const char *src_content, size_t src_content_len, bool is_symlink)
+{
+       return mountAddMountPt(nsjconf, /* head= */ false, src, dst, fstype, options, flags, isDir,
+                              mandatory, src_env, dst_env, src_content, src_content_len,
+                              is_symlink);
+}
+
 const char *mountDescribeMountPt(struct mounts_t *mpt)
 {
        static __thread char mount_pt_descr[4096];
diff --git a/mount.h b/mount.h
index c4deb0c..03fbf75 100644 (file)
--- a/mount.h
+++ b/mount.h
@@ -35,10 +35,14 @@ typedef enum {
 const char *mountFlagsToStr(uintptr_t flags);
 bool mountIsDir(const char *path);
 bool mountInitNs(struct nsjconf_t *nsjconf);
-bool mountAddMountPt(struct nsjconf_t *nsjconf, const char *src, const char *dst,
-                    const char *fstype, const char *options, uintptr_t flags, isDir_t isDir,
-                    bool mandatory, const char *src_env, const char *dst_env,
-                    const char *src_content, size_t src_content_len, bool is_symlink);
+bool mountAddMountPtHead(struct nsjconf_t *nsjconf, const char *src, const char *dst,
+                        const char *fstype, const char *options, uintptr_t flags, isDir_t isDir,
+                        bool mandatory, const char *src_env, const char *dst_env,
+                        const char *src_content, size_t src_content_len, bool is_symlink);
+bool mountAddMountPtTail(struct nsjconf_t *nsjconf, const char *src, const char *dst,
+                        const char *fstype, const char *options, uintptr_t flags, isDir_t isDir,
+                        bool mandatory, const char *src_env, const char *dst_env,
+                        const char *src_content, size_t src_content_len, bool is_symlink);
 const char *mountDescribeMountPt(struct mounts_t *mpt);
 
 #endif                         /* NS_MOUNT_H */