]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: don't support /etc/mtab by default
authorKarel Zak <kzak@redhat.com>
Thu, 14 Apr 2016 12:26:54 +0000 (14:26 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 14 Apr 2016 12:26:54 +0000 (14:26 +0200)
The file mtab is evil and already unused by mainstream distributions.

Now libmount is able to detect mtab->/proc/mounts and use
/proc/self/mountinfo if necessary. This heuristic seems overkill in
many cases. It's also dangerous on systems where mountinfo is strongly
required (systemd based distros).

This patch #ifdefs mtab code and forces libmount to always use
/proc/self/mountinfo.

The new configure option --enable-libmount-support-mtab is necessary
to enable old behavior to support mtab.

Signed-off-by: Karel Zak <kzak@redhat.com>
configure.ac
libmount/src/context.c
libmount/src/tab_parse.c
libmount/src/tab_update.c

index 48e994b10ae79f063081913089ac7b79daa1eb70..5a0040301d72478abb7f60db0388a0f3ae79808f 100644 (file)
@@ -962,13 +962,13 @@ AC_SUBST([LIBMOUNT_PATCH_VERSION], $PACKAGE_VERSION_RELEASE)
 AC_SUBST([LIBMOUNT_VERSION_INFO])
 AC_DEFINE_UNQUOTED([LIBMOUNT_VERSION], ["$LIBMOUNT_VERSION"], [libmount version string])
 
-AC_ARG_ENABLE([libmount-force-mountinfo],
-  AS_HELP_STRING([--enable-libmount-force-mountinfo], [ignore /etc/mtab in all situations (recommended for systemd)]),
-  [], [enable_libmount_force_mountinfo=no]
+AC_ARG_ENABLE([libmount-support-mtab],
+  AS_HELP_STRING([--enable-libmount-support-mtab], [support /etc/mtab (default is use /proc/self/mountinfo)]),
+  [], [enable_libmount_support_mtab=no]
 )
 
-AS_IF([test "x$enable_libmount_force_mountinfo" == xyes], [
-  AC_DEFINE([USE_LIBMOUNT_FORCE_MOUNTINFO], [1], [Define to 1 if want to ignore mtab in all situations.])
+AS_IF([test "x$enable_libmount_support_mtab" == xyes], [
+  AC_DEFINE([USE_LIBMOUNT_SUPPORT_MTAB], [1], [Define to 1 if want to support mtab.])
 ])
 
 
index e26135fb0a5daf2d72eb5cfe062139daf323b471..d9bda4375b15a8a90b414afc863fd2846a8ec2a9 100644 (file)
@@ -204,8 +204,10 @@ static int context_init_paths(struct libmnt_context *cxt, int writable)
 {
        assert(cxt);
 
+#ifdef USE_LIBMOUNT_SUPPORT_MTAB
        if (!cxt->mtab_path)
                cxt->mtab_path = mnt_get_mtab_path();
+#endif
        if (!cxt->utab_path)
                cxt->utab_path = mnt_get_utab_path();
 
@@ -218,13 +220,12 @@ static int context_init_paths(struct libmnt_context *cxt, int writable)
 
        DBG(CXT, ul_debugobj(cxt, "checking for writable tab files"));
 
-#ifdef USE_LIBMOUNT_FORCE_MOUNTINFO
        cxt->mtab_writable = 0;
-#else
-       mnt_has_regular_mtab(&cxt->mtab_path, &cxt->mtab_writable);
-#endif
 
+#ifdef USE_LIBMOUNT_SUPPORT_MTAB
+       mnt_has_regular_mtab(&cxt->mtab_path, &cxt->mtab_writable);
        if (!cxt->mtab_writable)
+#endif
                /* use /run/mount/utab if /etc/mtab is useless */
                mnt_has_regular_utab(&cxt->utab_path, &cxt->utab_writable);
 
@@ -1023,6 +1024,10 @@ int mnt_context_get_mtab(struct libmnt_context *cxt, struct libmnt_table **tb)
                                        cxt->table_fltrcb_data);
 
                mnt_table_set_cache(cxt->mtab, mnt_context_get_cache(cxt));
+
+               /*
+                * Note that mtab_path is NULL if mtab is useless or unsupported
+                */
                if (cxt->utab)
                        /* utab already parsed, don't parse it again */
                        rc = __mnt_table_parse_mtab(cxt->mtab,
index 23076bfc0d55bdfaf5516e28e46956d98fa702be..3253db71480b59a1ffd862fdd8c9eb9047692e1d 100644 (file)
@@ -679,7 +679,7 @@ err:
  * @tb: tab pointer
  * @filename: file
  *
- * Parses the whole table (e.g. /etc/mtab) and appends new records to the @tab.
+ * Parses the whole table (e.g. /etc/fstab) and appends new records to the @tab.
  *
  * The libmount parser ignores broken (syntax error) lines, these lines are
  * reported to the caller by the errcb() function (see mnt_table_set_parser_errcb()).
@@ -1051,6 +1051,8 @@ static struct libmnt_fs *mnt_table_merge_user_fs(struct libmnt_table *tb, struct
        return fs;
 }
 
+/* default filename is /proc/self/mountinfo
+ */
 int __mnt_table_parse_mtab(struct libmnt_table *tb, const char *filename,
                           struct libmnt_table *u_tb)
 {
@@ -1058,9 +1060,7 @@ int __mnt_table_parse_mtab(struct libmnt_table *tb, const char *filename,
 
        assert(tb);
 
-#ifdef USE_LIBMOUNT_FORCE_MOUNTINFO
-       DBG(TAB, ul_debugobj(tb, "mtab parse: ignore %s", filename ? filename : "mtab"));
-#else
+#ifdef USE_LIBMOUNT_SUPPORT_MTAB
        if (mnt_has_regular_mtab(&filename, NULL)) {
 
                DBG(TAB, ul_debugobj(tb, "force mtab usage [filename=%s]", filename));
@@ -1085,15 +1085,19 @@ int __mnt_table_parse_mtab(struct libmnt_table *tb, const char *filename,
         * useless /etc/mtab
         * -- read kernel information from /proc/self/mountinfo
         */
-       tb->fmt = MNT_FMT_MOUNTINFO;
-       rc = mnt_table_parse_file(tb, _PATH_PROC_MOUNTINFO);
+       tb->fmt = filename ? MNT_FMT_GUESS : MNT_FMT_MOUNTINFO;
+       rc = mnt_table_parse_file(tb, filename ? filename : _PATH_PROC_MOUNTINFO);
        if (rc) {
                /* hmm, old kernel? ...try /proc/mounts */
                tb->fmt = MNT_FMT_MTAB;
                return mnt_table_parse_file(tb, _PATH_PROC_MOUNTS);
        }
 
+       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)
@@ -1139,7 +1143,7 @@ read_utab:
 /**
  * mnt_table_parse_mtab:
  * @tb: table
- * @filename: overwrites default (/etc/mtab or $LIBMOUNT_MTAB) or NULL
+ * @filename: overwrites default or NULL
  *
  * This function parses /etc/mtab or /proc/self/mountinfo +
  * /run/mount/utabs or /proc/mounts.
index 631e1cd9fd229409b435d46f07992b67caa8ee03..d85cb89da5636bab1085ea787a4ae4ba5e174e03 100644 (file)
@@ -105,7 +105,9 @@ int mnt_update_set_filename(struct libmnt_update *upd, const char *filename,
 
        /* detect tab filename -- /etc/mtab or /run/mount/utab
         */
+#ifdef USE_LIBMOUNT_SUPPORT_MTAB
        mnt_has_regular_mtab(&path, &rw);
+#endif
        if (!rw) {
                path = NULL;
                mnt_has_regular_utab(&path, &rw);