]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: fix mnt_table_parse_mtab() logic
authorKarel Zak <kzak@redhat.com>
Fri, 15 Apr 2016 10:05:55 +0000 (12:05 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 15 Apr 2016 10:05:55 +0000 (12:05 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context_umount.c
libmount/src/tab_parse.c

index f3d473f5e5d654c7f31b68ae566bf405193d5c70..9a37901b51e5338423c0d53e617f51b9ab459b31 100644 (file)
@@ -67,10 +67,10 @@ int mnt_context_find_umount_fs(struct libmnt_context *cxt,
                return 1; /* empty string is not an error */
 
        /*
-        * The mtab file may be huge and on systems with utab we have to merge
+        * The mount table may be huge, and on systems with utab we have to merge
         * userspace mount options into /proc/self/mountinfo. This all is
-        * expensive. The mtab filter allows to filter out entries, then
-        * mtab and utab are very tiny files.
+        * expensive. The tab filter allows to filter out entries, then
+        * a mount table and utab are very tiny files.
         *
         * *but*... the filter uses mnt_fs_streq_{target,srcpath} functions
         * where LABEL, UUID or symlinks are canonicalized. It means that
index 3253db71480b59a1ffd862fdd8c9eb9047692e1d..45276a057996edf535fd016f8d3c855c07d887db 100644 (file)
@@ -1060,6 +1060,9 @@ int __mnt_table_parse_mtab(struct libmnt_table *tb, const char *filename,
 
        assert(tb);
 
+       if (filename)
+               DBG(TAB, ul_debugobj(tb, "%s reuested as mtab", filename));
+
 #ifdef USE_LIBMOUNT_SUPPORT_MTAB
        if (mnt_has_regular_mtab(&filename, NULL)) {
 
@@ -1077,16 +1080,18 @@ int __mnt_table_parse_mtab(struct libmnt_table *tb, const char *filename,
                if (!rc)
                        return 0;
                filename = NULL;        /* failed */
-       }
+       } else
+               filename = NULL;        /* mtab useless */
 #endif
-       DBG(TAB, ul_debugobj(tb, "mtab parse: #1 read mountinfo"));
 
-       /*
-        * useless /etc/mtab
-        * -- read kernel information from /proc/self/mountinfo
-        */
-       tb->fmt = filename ? MNT_FMT_GUESS : MNT_FMT_MOUNTINFO;
-       rc = mnt_table_parse_file(tb, filename ? filename : _PATH_PROC_MOUNTINFO);
+       if (!filename || strcmp(filename, _PATH_PROC_MOUNTINFO) == 0) {
+               filename = _PATH_PROC_MOUNTINFO;
+               tb->fmt = MNT_FMT_MOUNTINFO;
+               DBG(TAB, ul_debugobj(tb, "mtab parse: #1 read mountinfo"));
+       } else
+               tb->fmt = MNT_FMT_GUESS;
+
+       rc = mnt_table_parse_file(tb, filename);
        if (rc) {
                /* hmm, old kernel? ...try /proc/mounts */
                tb->fmt = MNT_FMT_MTAB;
@@ -1095,9 +1100,7 @@ int __mnt_table_parse_mtab(struct libmnt_table *tb, const char *filename,
 
        if (!is_mountinfo(tb))
                return 0;
-#ifdef USE_LIBMOUNT_SUPPORT_MTAB
 read_utab:
-#endif
        DBG(TAB, ul_debugobj(tb, "mtab parse: #2 read utab"));
 
        if (mnt_table_get_nents(tb) == 0)
@@ -1145,8 +1148,14 @@ read_utab:
  * @tb: table
  * @filename: overwrites default or NULL
  *
- * This function parses /etc/mtab or /proc/self/mountinfo +
- * /run/mount/utabs or /proc/mounts.
+ * The default filename is /proc/self/mountinfo. If the mount table is a
+ * mountinfo file then /run/mount/utabs is parsed too and both files are merged
+ * to the one libmnt_table.
+ *
+ * If libmount is compiled with classic mtab file support, and the /etc/mtab is
+ * a regular file then this file is parsed.
+ *
+ * It's strongly recommended to use NULL as a @filename to keep code portable.
  *
  * See also mnt_table_set_parser_errcb().
  *