]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: exec mount helpers with posixly correct argument order
authornilfsuser5678 <189666860+nilfsuser5678@users.noreply.github.com>
Fri, 29 Nov 2024 17:27:12 +0000 (17:27 +0000)
committernilfsuser5678 <189666860+nilfsuser5678@users.noreply.github.com>
Mon, 2 Dec 2024 13:57:35 +0000 (13:57 +0000)
This improves compatibility with non-gnu userspaces.

On systems where the libc provides posix getopt instead of gnu getopt,
mount helpers which use getopt to parse arguments will not parse
options which appear after non-option arguments. This patch ensures
mount/unmount work as expected in this situation.

mount: fix expected argument order for mount helpers in tests

libmount/src/context_mount.c
libmount/src/context_umount.c
tests/expected/mount/special-basic
tests/expected/mount/special-multi-types
tests/expected/mount/special-options
tests/expected/mount/special-user
tests/expected/mount/special-username

index 62a7dface535da4707dedae7cba6c54fe412f7e0..af2fd7ed4b73e731bded84118891c51b8b68de98 100644 (file)
@@ -429,31 +429,33 @@ static int exec_helper(struct libmnt_context *cxt)
                type = mnt_fs_get_fstype(cxt->fs);
 
                args[i++] = cxt->helper;                /* 1 */
-               args[i++] = mnt_fs_get_srcpath(cxt->fs);/* 2 */
-               args[i++] = mnt_fs_get_target(cxt->fs); /* 3 */
 
                if (mnt_context_is_sloppy(cxt))
-                       args[i++] = "-s";               /* 4 */
+                       args[i++] = "-s";               /* 2 */
                if (mnt_context_is_fake(cxt))
-                       args[i++] = "-f";               /* 5 */
+                       args[i++] = "-f";               /* 3 */
                if (mnt_context_is_nomtab(cxt))
-                       args[i++] = "-n";               /* 6 */
+                       args[i++] = "-n";               /* 4 */
                if (mnt_context_is_verbose(cxt))
-                       args[i++] = "-v";               /* 7 */
+                       args[i++] = "-v";               /* 5 */
                if (o) {
-                       args[i++] = "-o";               /* 8 */
-                       args[i++] = o;                  /* 9 */
+                       args[i++] = "-o";               /* 6 */
+                       args[i++] = o;                  /* 7 */
                }
                if (type
                    && strchr(type, '.')
                    && !endswith(cxt->helper, type)) {
-                       args[i++] = "-t";               /* 10 */
-                       args[i++] = type;               /* 11 */
+                       args[i++] = "-t";               /* 8 */
+                       args[i++] = type;               /* 9 */
                }
                if (namespace) {
-                       args[i++] = "-N";               /* 12 */
-                       args[i++] = namespace;          /* 13 */
+                       args[i++] = "-N";               /* 10 */
+                       args[i++] = namespace;          /* 11 */
                }
+
+               args[i++] = mnt_fs_get_srcpath(cxt->fs);/* 12 */
+               args[i++] = mnt_fs_get_target(cxt->fs); /* 13 */
+
                args[i] = NULL;                         /* 14 */
                for (i = 0; args[i]; i++)
                        DBG(CXT, ul_debugobj(cxt, "argv[%d] = \"%s\"",
index 64a1d884ba0f7400cafa43a7f0ec06f2917e79e6..3ae77778f59e82ec1407bdd62da1e3b9e3e5eafd 100644 (file)
@@ -711,29 +711,30 @@ static int exec_helper(struct libmnt_context *cxt)
                type = mnt_fs_get_fstype(cxt->fs);
 
                args[i++] = cxt->helper;                        /* 1 */
-               args[i++] = mnt_fs_get_target(cxt->fs);         /* 2 */
 
                if (mnt_context_is_nomtab(cxt))
-                       args[i++] = "-n";                       /* 3 */
+                       args[i++] = "-n";                       /* 2 */
                if (mnt_context_is_lazy(cxt))
-                       args[i++] = "-l";                       /* 4 */
+                       args[i++] = "-l";                       /* 3 */
                if (mnt_context_is_force(cxt))
-                       args[i++] = "-f";                       /* 5 */
+                       args[i++] = "-f";                       /* 4 */
                if (mnt_context_is_verbose(cxt))
-                       args[i++] = "-v";                       /* 6 */
+                       args[i++] = "-v";                       /* 5 */
                if (mnt_context_is_rdonly_umount(cxt))
-                       args[i++] = "-r";                       /* 7 */
+                       args[i++] = "-r";                       /* 6 */
                if (type
                    && strchr(type, '.')
                    && !endswith(cxt->helper, type)) {
-                       args[i++] = "-t";                       /* 8 */
-                       args[i++] = type;                       /* 9 */
+                       args[i++] = "-t";                       /* 7 */
+                       args[i++] = type;                       /* 8 */
                }
                if (namespace) {
-                       args[i++] = "-N";                       /* 10 */
-                       args[i++] = namespace;                  /* 11 */
+                       args[i++] = "-N";                       /* 9 */
+                       args[i++] = namespace;                  /* 10 */
                }
 
+               args[i++] = mnt_fs_get_target(cxt->fs);         /* 11 */
+
                args[i] = NULL;                                 /* 12 */
                for (i = 0; args[i]; i++)
                        DBG(CXT, ul_debugobj(cxt, "argv[%d] = \"%s\"",
index 99997d354fb56e3fd1fd3e80bc656602ad90d59a..ae1c368583e21652a3bfb3d3fd33462611f5bc42 100644 (file)
@@ -1 +1 @@
-/sbin/mount.mytest called with "/foo /bar -o rw"
+/sbin/mount.mytest called with "-o rw /foo /bar"
index 99997d354fb56e3fd1fd3e80bc656602ad90d59a..ae1c368583e21652a3bfb3d3fd33462611f5bc42 100644 (file)
@@ -1 +1 @@
-/sbin/mount.mytest called with "/foo /bar -o rw"
+/sbin/mount.mytest called with "-o rw /foo /bar"
index 820a74a9fc53f22918d654a9851cf4e6ce8c224a..b7fdad97e16adad4db7e7723f6fcd6358642a80f 100644 (file)
@@ -1 +1 @@
-/sbin/mount.mytest called with "/foo /bar -o rw,foo"
+/sbin/mount.mytest called with "-o rw,foo /foo /bar"
index 02c112e18a9e34960fd5081d7f410532a0c70519..1c79c32ea43c8aa778c6d806eb52fbf44b556f00 100644 (file)
@@ -1 +1 @@
-/sbin/mount.mytest called with "/foo /bar -o rw,user,noexec,nosuid,nodev,abc"
+/sbin/mount.mytest called with "-o rw,user,noexec,nosuid,nodev,abc /foo /bar"
index c192562906ca728d722507ce2e53c18e5d01015c..c8b94a7272e10b22657a9fc816dcedc5dfe319f9 100644 (file)
@@ -1 +1 @@
-/sbin/mount.mytest called with "/foo /bar -o rw,user=name,abc"
+/sbin/mount.mytest called with "-o rw,user=name,abc /foo /bar"