]> 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)
committerKarel Zak <kzak@redhat.com>
Tue, 10 Dec 2024 09:57:01 +0000 (10:57 +0100)
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
(cherry picked from commit 2d680b72ac61644e4ba177e6569d8ca13580c248)

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 e46558f93e11f61c15ee575237be03564cc6ba3b..1966f5be1b5b2ece71dd7ccf040920791058a76e 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 bf70ed2ee762fc5d067d67106e61245e0340d66d..f5de48848a8ec03ca413a1e41d4ec24712a6ff7e 100644 (file)
@@ -712,29 +712,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"