]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: read utab always when read mtab from /proc
authorKarel Zak <kzak@redhat.com>
Thu, 12 Feb 2015 12:14:52 +0000 (13:14 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 12 Feb 2015 12:21:08 +0000 (13:21 +0100)
Now libmount reads utab only when mtab filename is no explicitly
specified, but for example:

 mnt_table_parse_mtab(tb, "/proc/self/mountinfo");

ignores utab because filename points to regular file. This is mistake,
we wnat to read utab always when we read mount table from kernel.

Reported-by: Martin Pitt <martin.pitt@ubuntu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/mountP.h
libmount/src/tab.c
libmount/src/tab_parse.c

index 73f26482148181801cb7d3c52b323d2d5f8dfefb..cdd57cc5be0e292fb901fd5ee40dc0d4fa1375e6 100644 (file)
@@ -111,6 +111,7 @@ extern void mnt_free_filesystems(char **filesystems);
 extern char *mnt_get_kernel_cmdline_option(const char *name);
 
 /* tab.c */
+extern int is_mountinfo(struct libmnt_table *tb);
 extern int mnt_table_set_parser_fltrcb(        struct libmnt_table *tb,
                                        int (*cb)(struct libmnt_fs *, void *),
                                        void *data);
index 2b0a34371ded56639c2b2d4e5970a75345fa2c55..a012ecccaa4c3b1036f2bba6b91f95f5711f4473 100644 (file)
@@ -48,7 +48,7 @@
 #include "loopdev.h"
 #include "fileutils.h"
 
-static int is_mountinfo(struct libmnt_table *tb)
+int is_mountinfo(struct libmnt_table *tb)
 {
        struct libmnt_fs *fs;
 
index 05496f7602e2dbb2e57d1f2ae10974a0a328ade1..2757d0fee001a42d8e48f52eff39ad79795cfc67 100644 (file)
@@ -687,8 +687,9 @@ int mnt_table_parse_file(struct libmnt_table *tb, const char *filename)
                rc = mnt_table_parse_stream(tb, f, filename);
                fclose(f);
        } else
-               return -errno;
+               rc = -errno;
 
+       DBG(TAB, ul_debugobj(tb, "parsing done [filename=%s, rc=%d]", filename, rc));
        return rc;
 }
 
@@ -1053,14 +1054,24 @@ int __mnt_table_parse_mtab(struct libmnt_table *tb, const char *filename,
 
        if (mnt_has_regular_mtab(&filename, NULL)) {
 
-               DBG(TAB, ul_debugobj(tb, "force %s usage", filename));
+               DBG(TAB, ul_debugobj(tb, "force mtab usage [filename=%s]", filename));
 
                rc = mnt_table_parse_file(tb, filename);
+
+               /*
+                * If @filename forces us to read from /proc then also read
+                * utab file to merge userspace mount options.
+                */
+               if (rc == 0 && is_mountinfo(tb))
+                       goto read_utab;
+
                if (!rc)
                        return 0;
                filename = NULL;        /* failed */
        }
 
+       DBG(TAB, ul_debugobj(tb, "mtab parse: #1 read mountinfo"));
+
        /*
         * useless /etc/mtab
         * -- read kernel information from /proc/self/mountinfo
@@ -1073,6 +1084,9 @@ int __mnt_table_parse_mtab(struct libmnt_table *tb, const char *filename,
                return mnt_table_parse_file(tb, _PATH_PROC_MOUNTS);
        }
 
+read_utab:
+       DBG(TAB, ul_debugobj(tb, "mtab parse: #2 read utab"));
+
        if (mnt_table_get_nents(tb) == 0)
                return 0;                       /* empty, ignore utab */
        /*
@@ -1080,6 +1094,7 @@ int __mnt_table_parse_mtab(struct libmnt_table *tb, const char *filename,
         */
        if (!u_tb) {
                const char *utab = mnt_get_utab_path();
+
                if (!utab || is_file_empty(utab))
                        return 0;
 
@@ -1094,6 +1109,8 @@ int __mnt_table_parse_mtab(struct libmnt_table *tb, const char *filename,
                priv_utab = 1;
        }
 
+       DBG(TAB, ul_debugobj(tb, "mtab parse: #3 merge utab"));
+
        if (rc == 0) {
                struct libmnt_fs *u_fs;
                struct libmnt_iter itr;