From 60d29f827b94097fb718dcb02fad6ccb571bdb2b Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 12 Feb 2015 13:14:52 +0100 Subject: 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 Signed-off-by: Karel Zak --- libmount/src/mountP.h | 1 + libmount/src/tab.c | 2 +- libmount/src/tab_parse.c | 21 +++++++++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) (limited to 'libmount') diff --git a/libmount/src/mountP.h b/libmount/src/mountP.h index 73f264821..cdd57cc5b 100644 --- a/libmount/src/mountP.h +++ b/libmount/src/mountP.h @@ -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); diff --git a/libmount/src/tab.c b/libmount/src/tab.c index 2b0a34371..a012eccca 100644 --- a/libmount/src/tab.c +++ b/libmount/src/tab.c @@ -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; diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c index 05496f760..2757d0fee 100644 --- a/libmount/src/tab_parse.c +++ b/libmount/src/tab_parse.c @@ -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; -- cgit v1.2.3-55-g7522