From be1a5180596aa3a413e9c8047d0d25f4704756ef Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 5 Aug 2010 12:35:54 +0200 Subject: libmount: correctly use "none" values Signed-off-by: Karel Zak --- shlibs/mount/src/fs.c | 27 +++++++++++++++------------ shlibs/mount/src/tab_parse.c | 5 ++++- shlibs/mount/src/utils.c | 8 ++++++-- 3 files changed, 25 insertions(+), 15 deletions(-) (limited to 'shlibs/mount') diff --git a/shlibs/mount/src/fs.c b/shlibs/mount/src/fs.c index 7fc5e8825..b0de9eaef 100644 --- a/shlibs/mount/src/fs.c +++ b/shlibs/mount/src/fs.c @@ -193,10 +193,10 @@ int __mnt_fs_set_source(mnt_fs *fs, char *source) { assert(fs); - if (!source) - return -1; + if (source && !strcmp(source, "none")) + source = NULL; - if (strchr(source, '=')) { + if (source && strchr(source, '=')) { char *name, *val; if (blkid_parse_tag_string(source, &name, &val) != 0) @@ -401,20 +401,23 @@ const char *mnt_fs_get_optstr(mnt_fs *fs) */ int mnt_fs_set_optstr(mnt_fs *fs, const char *optstr) { - char *p, *v, *f; + char *p = NULL, *v = NULL, *f = NULL; assert(fs); - if (!fs || !optstr) - return -1; - if (mnt_split_optstr((char *) optstr, NULL, &v, &f, 0, 0)) + if (!fs) return -1; - p = strdup(optstr); - if (!p) { - free(v); - free(f); - return -1; + if (optstr) { + if (mnt_split_optstr((char *) optstr, NULL, &v, &f, 0, 0)) + return -1; + + p = strdup(optstr); + if (!p) { + free(v); + free(f); + return -1; + } } free(fs->optstr); diff --git a/shlibs/mount/src/tab_parse.c b/shlibs/mount/src/tab_parse.c index 4ab39fbd1..6f8308e50 100644 --- a/shlibs/mount/src/tab_parse.c +++ b/shlibs/mount/src/tab_parse.c @@ -206,7 +206,10 @@ static int mnt_parse_mountinfo_line(mnt_fs *fs, char *s) fs->fs_optstr = next_word(&s); if (!fs->fs_optstr) return 1; - + if (!strcmp(fs->fs_optstr, "none")) { + free(fs->fs_optstr); + fs->fs_optstr = NULL; + } return 0; } diff --git a/shlibs/mount/src/utils.c b/shlibs/mount/src/utils.c index 55e060581..15785df2a 100644 --- a/shlibs/mount/src/utils.c +++ b/shlibs/mount/src/utils.c @@ -325,8 +325,10 @@ int mnt_has_regular_mtab(void) /** * mnt_get_writable_mtab_path: * - * Returns: pointer to the static string with path to the file with userspace - * mount options (classic /etc/mtab or /var/run/mount/mountinfo) + * It's not error if this function return NULL and errno is not set. In case of + * error the errno is set by open(2). + * + * Returns: pointer to the static string with path to mtab or NULL. */ const char *mnt_get_writable_mtab_path(void) { @@ -336,6 +338,8 @@ const char *mnt_get_writable_mtab_path(void) mtab = !lstat(_PATH_MOUNTED, &mst); info = !stat(MNT_PATH_RUNDIR, &ist); + errno = 0; + /* A) mtab is symlink, /var/run/mount is available */ if (mtab && S_ISLNK(mst.st_mode) && info) { int fd = open(MNT_PATH_MOUNTINFO, O_RDWR | O_CREAT, 0644); -- cgit v1.2.3-55-g7522