libmount: read utab always when read mtab from /proc

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>
This commit is contained in:
Karel Zak 2015-02-12 13:14:52 +01:00
parent 9c277ede65
commit 60d29f827b
3 changed files with 21 additions and 3 deletions

View 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);

View 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;

View 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;