]> git.proxmox.com Git - mirror_lxc.git/commitdiff
utils: add shared mount point detection
authorLiza Tretyakova <elizabet.tretyakova@gmail.com>
Wed, 2 May 2018 07:47:15 +0000 (10:47 +0300)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sun, 22 Jul 2018 13:25:15 +0000 (15:25 +0200)
Signed-off-by: Liza Tretyakova <elizabet.tretyakova@gmail.com>
src/lxc/utils.c
src/lxc/utils.h

index dd6cdc91a17aafb52856af3aa0ff90dbc17d6a17..bad355265575f068a83f5565955f586f46fc2844 100644 (file)
@@ -1219,19 +1219,12 @@ uint64_t fnv_64a_buf(void *buf, size_t len, uint64_t hval)
        return hval;
 }
 
-/*
- * Detect whether / is mounted MS_SHARED.  The only way I know of to
- * check that is through /proc/self/mountinfo.
- * I'm only checking for /.  If the container rootfs or mount location
- * is MS_SHARED, but not '/', then you're out of luck - figuring that
- * out would be too much work to be worth it.
- */
-int detect_shared_rootfs(void)
+bool is_shared_mountpoint(const char *path)
 {
-       char buf[LXC_LINELEN], *p;
+       char buf[LXC_LINELEN];
        FILE *f;
        int i;
-       char *p2;
+       char *p, *p2;
 
        f = fopen("/proc/self/mountinfo", "r");
        if (!f)
@@ -1248,17 +1241,31 @@ int detect_shared_rootfs(void)
                        continue;
 
                *p2 = '\0';
-               if (strcmp(p + 1, "/") == 0) {
-                       /* This is '/'. Is it shared? */
+               if (strcmp(p + 1, path) == 0) {
+                       /* This is the path. Is it shared? */
                        p = strchr(p2 + 1, ' ');
                        if (p && strstr(p, "shared:")) {
                                fclose(f);
-                               return 1;
+                               return true;
                        }
                }
        }
 
        fclose(f);
+       return false;
+}
+
+/*
+ * Detect whether / is mounted MS_SHARED.  The only way I know of to
+ * check that is through /proc/self/mountinfo.
+ * I'm only checking for /.  If the container rootfs or mount location
+ * is MS_SHARED, but not '/', then you're out of luck - figuring that
+ * out would be too much work to be worth it.
+ */
+int detect_shared_rootfs(void)
+{
+       if (is_shared_mountpoint("/"))
+               return 1;
        return 0;
 }
 
index 295e7862ccf9e5880136dab63c3c941ce056133a..46ef2850494228ce625f1a45cdb2de15db3a9243 100644 (file)
@@ -502,6 +502,7 @@ extern bool dir_exists(const char *path);
 #define FNV1A_64_INIT ((uint64_t)0xcbf29ce484222325ULL)
 extern uint64_t fnv_64a_buf(void *buf, size_t len, uint64_t hval);
 
+extern bool is_shared_mountpoint(const char *path);
 extern int detect_shared_rootfs(void);
 extern bool detect_ramfs_rootfs(void);
 extern char *on_path(const char *cmd, const char *rootfs);