From 7c118af7a1e898a258f6237e3a12faffe5844c0c Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 8 Nov 2010 12:21:41 +0100 Subject: [PATCH] libmount: add debug messages and fix typos in tab_update Signed-off-by: Karel Zak --- shlibs/mount/src/tab_parse.c | 6 +++++- shlibs/mount/src/tab_update.c | 14 +++++++++----- shlibs/mount/src/utils.c | 25 ++++++++++++++++++------- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/shlibs/mount/src/tab_parse.c b/shlibs/mount/src/tab_parse.c index a1857a44..af500832 100644 --- a/shlibs/mount/src/tab_parse.c +++ b/shlibs/mount/src/tab_parse.c @@ -148,7 +148,11 @@ static int mnt_parse_mountinfo_line(mnt_fs *fs, char *s) } else unmangle_string(src); - unmangle_string(fs->fs_optstr); + if (!strcmp(fs->fs_optstr, "none")) { + free(fs->fs_optstr); + fs->fs_optstr = NULL; + } else + unmangle_string(fs->fs_optstr); rc = __mnt_fs_set_fstype_ptr(fs, fstype); if (!rc) diff --git a/shlibs/mount/src/tab_update.c b/shlibs/mount/src/tab_update.c index 09c9cdfa..99b2a890 100644 --- a/shlibs/mount/src/tab_update.c +++ b/shlibs/mount/src/tab_update.c @@ -676,18 +676,22 @@ static int update(const char *target, mnt_fs *fs, unsigned long mountflags) if (rc && writable) upd = mnt_new_update(TRUE); - else - return -EACCES; + else { + fprintf(stderr, "utab useless: %m\n"); + return -1; + } } rc = mnt_update_set_fs(upd, mountflags, target, fs); - if (rc) - goto done; if (rc == 1) { - fprintf(stderr, "update is unnecessary\n"); + /* update is unnecessary */ rc = 0; goto done; } + if (rc) { + fprintf(stderr, "failed to set FS\n"); + goto done; + } /* [... here should be mount(2) call ...] */ diff --git a/shlibs/mount/src/utils.c b/shlibs/mount/src/utils.c index 410028fa..0f17edfe 100644 --- a/shlibs/mount/src/utils.c +++ b/shlibs/mount/src/utils.c @@ -448,6 +448,8 @@ int mnt_has_regular_mtab(const char **mtab, int *writable) int rc; const char *filename = mtab && *mtab ? *mtab : mnt_get_mtab_path(); + if (writable) + *writable = 0; if (mtab && !*mtab) *mtab = filename; @@ -462,17 +464,21 @@ int mnt_has_regular_mtab(const char **mtab, int *writable) *writable = !try_write(filename); return 1; } - return 0; /* it's not regular file */ + goto done; } /* try to create the file */ if (writable) { *writable = !try_write(filename); - return *writable; + if (*writable) + return 1; } +done: + DBG(UTILS, mnt_debug("%s: irregular/non-writable", filename)); return 0; } + /** * * mnt_has_regular_utab: @@ -492,6 +498,8 @@ int mnt_has_regular_utab(const char **utab, int *writable) int rc; const char *filename = utab && *utab ? *utab : mnt_get_utab_path(); + if (writable) + *writable = 0; if (utab && !*utab) *utab = filename; @@ -503,28 +511,31 @@ int mnt_has_regular_utab(const char **utab, int *writable) /* file exist */ if (S_ISREG(st.st_mode)) { if (writable) - *writable = try_write(filename); + *writable = !try_write(filename); return 1; } - return 0; /* it's not regular file */ + goto done; /* it's not regular file */ } if (writable) { char *dirname = strdup(filename); if (!dirname) - return 0; + goto done; stripoff_last_component(dirname); /* remove filename */ rc = mkdir(dirname, 755); free(dirname); if (rc && errno != EEXIST) - return 0; /* probably EACCES */ + goto done; /* probably EACCES */ *writable = !try_write(filename); - return *writable; + if (*writable) + return 1; } +done: + DBG(UTILS, mnt_debug("%s: irregular/non-writable file", filename)); return 0; } -- 2.39.5