From 051aacd1885f42e34ec58f76768a5a83114d34b3 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 30 Sep 2010 12:08:36 +0200 Subject: [PATCH] libmount: update mtab after mount(2) Signed-off-by: Karel Zak --- shlibs/mount/src/context.c | 59 +++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/shlibs/mount/src/context.c b/shlibs/mount/src/context.c index a6cc8688..773c6dd7 100644 --- a/shlibs/mount/src/context.c +++ b/shlibs/mount/src/context.c @@ -1489,22 +1489,49 @@ int mnt_context_mount_fs(mnt_context *cxt) if (!(cxt->flags & MNT_FL_MOUNTDATA)) cxt->mountdata = (char *) mnt_fs_get_fs_optstr(cxt->fs); - if (type && !strchr(type, ',')) + if (type && !strchr(type, ',')) { rc = mnt_context_do_mount(cxt, type); - + if (rc) + return rc; + } /* TODO: try all filesystems from comma separated list of types */ /* TODO: try all filesystems from /proc/filesystems and /etc/filesystems */ - /* TODO: if mtab update is expected then checkif the target is really - * mounted read-write to avoid 'ro' in mtab and 'rw' in /proc/mounts. + return rc; +} + +/** + * mnt_context_post_mount: + * @cxt: mount context + * + * Updates mtab, etc. This function should be always called after + * mnt_context_do_mount(). + * + * Returns: 0 on success, and negative number in case of error. + */ +int mnt_context_post_mount(mnt_context *cxt) +{ + int rc = 0; + + if (!cxt) + return -EINVAL; + /* + * Update /etc/mtab or /var/run/mount/mountinfo */ + if (!cxt->syscall_errno && !cxt->helper_name && + !(cxt->flags & MNT_FL_NOMTAB) && + cxt->update && !mnt_update_is_pointless(cxt->update)) { + + /* TODO: if mtab update is expected then checkif the target is really + * mounted read-write to avoid 'ro' in mtab and 'rw' in /proc/mounts. + */ + rc = mnt_update_file(cxt->update); + } return rc; } -/* TODO: mnt_context_post_mount() */ - /** * mnt_context_get_mount_error: * @cxt: mount context @@ -1523,6 +1550,16 @@ int mnt_context_get_mount_error(mnt_context *cxt, char *buf, size_t bufsiz) #ifdef TEST_PROGRAM +mnt_lock *lock; + +static void lock_fallback(void) +{ + if (lock) { + mnt_unlock_file(lock); + mnt_free_lock(lock); + } +} + int test_mount(struct mtest *ts, int argc, char *argv[]) { int idx = 1, rc = 0; @@ -1559,11 +1596,19 @@ int test_mount(struct mtest *ts, int argc, char *argv[]) if (rc) printf("failed to prepare mount\n"); else { + lock = mnt_context_get_lock(cxt); + if (lock) + atexit(lock_fallback); + rc = mnt_context_mount_fs(cxt); if (rc) printf("failed to mount\n"); - else + else { printf("successfully mounted"); + rc = mnt_context_post_mount(cxt); + if (rc) + printf("mtab update failed\n"); + } } mnt_free_context(cxt); -- 2.39.5