From: Karel Zak Date: Wed, 30 Mar 2011 13:40:56 +0000 (+0200) Subject: libmount: add phelper= support X-Git-Tag: v2.20-rc1~410 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4b658e0997ad63088782635acab0bca9bb46ad3d;p=thirdparty%2Futil-linux.git libmount: add phelper= support Signed-off-by: Karel Zak --- diff --git a/shlibs/mount/src/context_umount.c b/shlibs/mount/src/context_umount.c index 0e69fe5f9f..08b0fd46c5 100644 --- a/shlibs/mount/src/context_umount.c +++ b/shlibs/mount/src/context_umount.c @@ -149,6 +149,32 @@ static int mnt_loopdev_associated_fs(const char *devname, struct libmnt_fs *fs) return 0; } +static int prepare_helper_from_options(struct libmnt_context *cxt, + const char *name) +{ + char *suffix = NULL; + const char *opts; + size_t valsz; + + if (cxt->flags & MNT_FL_NOHELPERS) + return 0; + + opts = mnt_fs_get_user_options(cxt->fs); + if (!opts) + return 0; + + if (mnt_optstr_get_option((char *) opts, name, &suffix, &valsz)) + return 0; + + suffix = strndup(suffix, valsz); + if (!suffix) + return -ENOMEM; + + DBG(CXT, mnt_debug_h(cxt, "umount: umount.%s %s requested", suffix, name)); + + return mnt_context_prepare_helper(cxt, "umount", suffix); +} + /* * Note that cxt->fs contains relevant mtab entry! */ @@ -179,21 +205,10 @@ static int evaluate_permissions(struct libmnt_context *cxt) goto eperm; } - if (!(cxt->flags & MNT_FL_NOHELPERS) && - (cxt->user_mountflags & MNT_MS_UHELPER)) { - - char *suffix = NULL; - char *o = (char *) mnt_fs_get_user_options(cxt->fs); - size_t valsz; - - rc = mnt_optstr_get_option(o, "uhelper", &suffix, &valsz); - if (!rc) { - suffix = strndup(suffix, valsz); - if (!suffix) - return -ENOMEM; - rc = mnt_context_prepare_helper(cxt, "umount", suffix); - } - if (rc < 0) + if (cxt->user_mountflags & MNT_MS_UHELPER) { + /* on uhelper= mount option based helper */ + rc = prepare_helper_from_options(cxt, "uhelper"); + if (rc) return rc; if (cxt->helper) return 0; /* we'll call /sbin/umount. */ @@ -566,8 +581,18 @@ int mnt_context_prepare_umount(struct libmnt_context *cxt) rc = evaluate_permissions(cxt); if (!rc) rc = mnt_context_prepare_target(cxt); - if (!rc && !cxt->helper) - rc = mnt_context_prepare_helper(cxt, "umount", NULL); + + if (!rc && !cxt->helper) { + + if (!cxt->restricted && (cxt->user_mountflags & MNT_MS_PHELPER)) + /* on phelper= mount option based helper */ + rc = prepare_helper_from_options(cxt, "phelper"); + + if (!rc && !cxt->helper) + /* on fstype based helper */ + rc = mnt_context_prepare_helper(cxt, "umount", NULL); + } + /* TODO if ((cxt->flags & MNT_FL_LOOPDEL) && (!mnt_is_loopdev(src) || mnt_loopdev_is_autoclear(src))) diff --git a/shlibs/mount/src/libmount.h.in b/shlibs/mount/src/libmount.h.in index d7e7a51729..6138224685 100644 --- a/shlibs/mount/src/libmount.h.in +++ b/shlibs/mount/src/libmount.h.in @@ -439,6 +439,7 @@ extern int mnt_context_do_umount(struct libmnt_context *cxt); #define MNT_MS_LOOP (1 << 9) #define MNT_MS_NOFAIL (1 << 10) #define MNT_MS_UHELPER (1 << 11) +#define MNT_MS_PHELPER (1 << 12) /* * mount(2) MS_* masks (MNT_MAP_LINUX map) diff --git a/shlibs/mount/src/optmap.c b/shlibs/mount/src/optmap.c index 89ec101c3f..4924e9ae32 100644 --- a/shlibs/mount/src/optmap.c +++ b/shlibs/mount/src/optmap.c @@ -155,6 +155,8 @@ static const struct libmnt_optmap userspace_opts_map[] = { "uhelper=", MNT_MS_UHELPER }, /* /sbin/umount. */ + { "phelper=", MNT_MS_PHELPER }, /* /sbin/umount. */ + { NULL, 0, 0 } };