From f501724264bec87ecf717b5ab2e0ccafc50039d3 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 25 Jan 2011 00:26:47 +0100 Subject: [PATCH] libmount: improve status check, minor cleanups Signed-off-by: Karel Zak --- shlibs/mount/src/context.c | 25 +++++++++++++++++++++++-- shlibs/mount/src/context_mount.c | 5 +++-- shlibs/mount/src/fs.c | 30 +++++++++++++++--------------- shlibs/mount/src/libmount.h.in | 1 + shlibs/mount/src/libmount.sym | 1 + shlibs/mount/src/utils.c | 2 +- 6 files changed, 44 insertions(+), 20 deletions(-) diff --git a/shlibs/mount/src/context.c b/shlibs/mount/src/context.c index bfa0292f..ed9f223a 100644 --- a/shlibs/mount/src/context.c +++ b/shlibs/mount/src/context.c @@ -1292,7 +1292,7 @@ int mnt_context_update_tabs(struct libmnt_context *cxt) return 0; } if (cxt->syscall_status) { - DBG(CXT, mnt_debug_h(cxt, "don't update: syscall failed")); + DBG(CXT, mnt_debug_h(cxt, "don't update: syscall failed/not called")); return 0; } @@ -1471,13 +1471,32 @@ int mnt_context_apply_fstab(struct libmnt_context *cxt) * mnt_context_get_status: * @cxt: mount context * - * Returns: 1 if /sbin/mount.type or mount(2) syscall was successfull or 0. + * Returns: 0 if /sbin/mount.type or mount(2) syscall was successfull or -errno. */ int mnt_context_get_status(struct libmnt_context *cxt) { return cxt && (!cxt->syscall_status || !cxt->helper_exec_status); } +/** + * mnt_context_set_syscall_status: + * @cxt: mount context + * @status: mount(2) return code + * + * This function should be used if [u]mount(2) syscall was NOT called by + * libmount (mnt_mount_context() or mnt_context_do_mount()) only. + * + * Returns: 0 or negative number in case of error. + */ +int mnt_context_set_syscall_status(struct libmnt_context *cxt, int status) +{ + if (!cxt) + return -EINVAL; + + cxt->syscall_status = status; + return 0; +} + /** * mnt_context_strerror * @cxt: context @@ -1514,6 +1533,8 @@ int mnt_context_init_helper(struct libmnt_context *cxt, int flags) if (!rc) return set_flag(cxt, MNT_FL_HELPER, 1); + + DBG(CXT, mnt_debug_h(cxt, "initialized for [u]mount. helper")); return rc; } diff --git a/shlibs/mount/src/context_mount.c b/shlibs/mount/src/context_mount.c index 367d1341..0b6c3d86 100644 --- a/shlibs/mount/src/context_mount.c +++ b/shlibs/mount/src/context_mount.c @@ -515,7 +515,7 @@ int mnt_context_prepare_mount(struct libmnt_context *cxt) if (!rc) rc = mnt_context_prepare_srcpath(cxt); if (!rc) - rc = mnt_context_prepare_target(cxt); + rc = mnt_context_prepare_target(cxt); if (!rc) rc = mnt_context_guess_fstype(cxt); if (!rc) @@ -605,7 +605,8 @@ int mnt_mount_context(struct libmnt_context *cxt) * mnt_context_finalize_mount: * @cxt: context * - * Mtab update, etc. Unnecessary for mnt_context_mount(). + * Mtab update, etc. Unnecessary for mnt_context_mount(), but should be called + * after mnt_context_do_mount(). See also mnt_context_set_syscall_status(). * * Returns: negative number on error, 0 on success. */ diff --git a/shlibs/mount/src/fs.c b/shlibs/mount/src/fs.c index 03fe4bbe..1477812f 100644 --- a/shlibs/mount/src/fs.c +++ b/shlibs/mount/src/fs.c @@ -299,14 +299,16 @@ int __mnt_fs_set_source_ptr(struct libmnt_fs *fs, char *source) */ int mnt_fs_set_source(struct libmnt_fs *fs, const char *source) { - char *p; + char *p = NULL; int rc; - if (!fs && !source) + if (!fs) return -EINVAL; - p = strdup(source); - if (!p) - return -ENOMEM; + if (source) { + p = strdup(source); + if (!p) + return -ENOMEM; + } rc = __mnt_fs_set_source_ptr(fs, p); if (rc) @@ -381,15 +383,17 @@ const char *mnt_fs_get_target(struct libmnt_fs *fs) */ int mnt_fs_set_target(struct libmnt_fs *fs, const char *target) { - char *p; + char *p = NULL; assert(fs); - if (!fs || !target) + if (!fs) return -EINVAL; - p = strdup(target); - if (!p) - return -ENOMEM; + if (target) { + p = strdup(target); + if (!p) + return -ENOMEM; + } free(fs->target); fs->target = p; @@ -444,7 +448,6 @@ int __mnt_fs_set_fstype_ptr(struct libmnt_fs *fs, char *fstype) int mnt_fs_set_fstype(struct libmnt_fs *fs, const char *fstype) { char *p = NULL; - int rc; if (!fs) return -EINVAL; @@ -453,10 +456,7 @@ int mnt_fs_set_fstype(struct libmnt_fs *fs, const char *fstype) if (!p) return -ENOMEM; } - rc = __mnt_fs_set_fstype_ptr(fs, p); - if (rc) - free(p); - return rc; + return __mnt_fs_set_fstype_ptr(fs, p); } /* diff --git a/shlibs/mount/src/libmount.h.in b/shlibs/mount/src/libmount.h.in index 6ac24ca1..153b28ae 100644 --- a/shlibs/mount/src/libmount.h.in +++ b/shlibs/mount/src/libmount.h.in @@ -421,6 +421,7 @@ extern int mnt_mount_context(struct libmnt_context *cxt); extern int mnt_context_prepare_mount(struct libmnt_context *cxt); extern int mnt_context_do_mount(struct libmnt_context *cxt); extern int mnt_context_finalize_mount(struct libmnt_context *cxt); +extern int mnt_context_set_syscall_status(struct libmnt_context *cxt, int status); extern int mnt_context_do_umount(struct libmnt_context *cxt); diff --git a/shlibs/mount/src/libmount.sym b/shlibs/mount/src/libmount.sym index 4709a8a2..160174ea 100644 --- a/shlibs/mount/src/libmount.sym +++ b/shlibs/mount/src/libmount.sym @@ -57,6 +57,7 @@ global: mnt_context_set_options_pattern; mnt_context_set_optsmode; mnt_context_set_source; + mnt_context_set_syscall_status; mnt_context_set_target; mnt_context_set_user_mflags; mnt_context_strerror; diff --git a/shlibs/mount/src/utils.c b/shlibs/mount/src/utils.c index 35d43452..cb0ed1ca 100644 --- a/shlibs/mount/src/utils.c +++ b/shlibs/mount/src/utils.c @@ -112,7 +112,7 @@ int mnt_fstype_is_pseudofs(const char *type) strcmp(type, "tmpfs") == 0 || strcmp(type, "sysfs") == 0 || strcmp(type, "devpts") == 0|| - strcmp(type, "cgroups") == 0 || + strcmp(type, "cgroup") == 0 || strcmp(type, "devfs") == 0 || strcmp(type, "dlmfs") == 0 || strcmp(type, "cpuset") == 0 || -- 2.39.5