summaryrefslogtreecommitdiffstats
path: root/libmount/src/tab_parse.c
diff options
context:
space:
mode:
authorKarel Zak2017-11-08 16:47:40 +0100
committerKarel Zak2017-11-08 17:03:59 +0100
commit06ff935ec3ad2290025b555ff32b590680af565f (patch)
treee9650c7c99554bae3fa903e865048f99509fd806 /libmount/src/tab_parse.c
parentlibmount: Allow MNT_FORCE and MNT_DETACH at umount (diff)
downloadkernel-qcow2-util-linux-06ff935ec3ad2290025b555ff32b590680af565f.tar.gz
kernel-qcow2-util-linux-06ff935ec3ad2290025b555ff32b590680af565f.tar.xz
kernel-qcow2-util-linux-06ff935ec3ad2290025b555ff32b590680af565f.zip
libmount: fix access() utab write test
The commit c08396c7691e1e6a04b6b45892e7e4612ceed8d7 replaces open(O_CREATE) with ecaccess(). Unfortunately, another code depends on the original behavior. * let's make utab when really necessary rather than in the try_write() test * __mnt_new_table_from_file() returns NULL if tab-file does not exists. This is incorrect for tab_update.c stuff. We need empty table in this case. * we can check /run/mount/ directory for write access if eaccess(filename) return ENOENT (because file does not exist) Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/tab_parse.c')
-rw-r--r--libmount/src/tab_parse.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c
index b17a22913..02dd0c961 100644
--- a/libmount/src/tab_parse.c
+++ b/libmount/src/tab_parse.c
@@ -838,7 +838,7 @@ int mnt_table_parse_dir(struct libmnt_table *tb, const char *dirname)
return __mnt_table_parse_dir(tb, dirname);
}
-struct libmnt_table *__mnt_new_table_from_file(const char *filename, int fmt)
+struct libmnt_table *__mnt_new_table_from_file(const char *filename, int fmt, int empty_for_enoent)
{
struct libmnt_table *tb;
struct stat st;
@@ -846,7 +846,8 @@ struct libmnt_table *__mnt_new_table_from_file(const char *filename, int fmt)
if (!filename)
return NULL;
if (stat(filename, &st))
- return NULL;
+ return empty_for_enoent ? mnt_new_table() : NULL;
+
tb = mnt_new_table();
if (tb) {
DBG(TAB, ul_debugobj(tb, "new tab for file: %s", filename));
@@ -875,7 +876,7 @@ struct libmnt_table *mnt_new_table_from_file(const char *filename)
if (!filename)
return NULL;
- return __mnt_new_table_from_file(filename, MNT_FMT_GUESS);
+ return __mnt_new_table_from_file(filename, MNT_FMT_GUESS, 0);
}
/**