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>
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.])
])
{
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();
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);
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,
* @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()).
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)
{
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));
* 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)
/**
* 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.
/* 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);