]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: add phelper= support
authorKarel Zak <kzak@redhat.com>
Wed, 30 Mar 2011 13:40:56 +0000 (15:40 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 30 Mar 2011 13:40:56 +0000 (15:40 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
shlibs/mount/src/context_umount.c
shlibs/mount/src/libmount.h.in
shlibs/mount/src/optmap.c

index 0e69fe5f9faa2a80e0e9a68852b1aee11d747767..08b0fd46c55614a4229cd95aeba095c5217012cd 100644 (file)
@@ -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.<uhelper> */
@@ -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)))
index d7e7a51729a431bd79fbf4839b831b42702bdce8..61382246859b57b6e1fcca18c53966cab58e511b 100644 (file)
@@ -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)
index 89ec101c3f3bc673cb1e55acdc7ae7e5ef8b67a9..4924e9ae326c9ed9430398b58ea014d7cc8cbe65 100644 (file)
@@ -155,6 +155,8 @@ static const struct libmnt_optmap userspace_opts_map[] =
 
    { "uhelper=", MNT_MS_UHELPER },                        /* /sbin/umount.<helper> */
 
+   { "phelper=", MNT_MS_PHELPER },                        /* /sbin/umount.<helper> */
+
    { NULL, 0, 0 }
 };